Thursday, 13 October 2011

Array in flash

import flash.display.MovieClip;
import flash.events.Event;

var blockArray:Array=new Array();
// create array called block array


for (var i:int = 0; i <15; i++){
// will loop cube 15 times
var cube:MovieClip = new box();
//brings in box from library
cube.x=Math.random()*550
//places cube from library along width of stage
cube.y=Math.random()*400
//places cube from library along hieght of stage
addChild(cube);
// duplicates cube from library

blockArray[i]=cube
// numbers the cubes
}

stage.addEventListener(Event.ENTER_FRAME, checkhit);
//listen to stage on every frame
function checkhit(myevent:Event):void{
for (var i:int = 0; i < 15; i++){
if (blockArray[i].hitTestPoint(mouseX,mouseY,true)){
// if any of the cubes get hit by the mouse in any direction (x,y) and if mouse hit whole object or reg point
blockArray[i].alpha=.3;
}// if box get hit make box transparent
}
}

No comments:

Post a Comment