var blockArray:Array=new Array();
//create an array called block array
for (var i:int = 0; i <15; i++) { // This tells that i = 0, and if i is less than 15, then 15 of the object is created.
var cube:MovieClip = new box (); //this takes box from the library and calls its actions as cube.
cube.x=Math.random()*400 //this spawns cube on a random number on the x axis
cube.y=Math.random()*400 // this spawns the cube on a random number on the y axis at the same time
addChild(cube);
blockArray[i]=cube;
//i is the number and keeps adding until the limit above which is 15
}
stage.addEventListener(Event.ENTER_FRAME, checkhit);
//listens to command
function checkhit(myevent:Event) :void {
for (var i:int = 0; i < 15; i++) {
//create a loop
if (blockArray[i].hitTestPoint(mouseX,mouseY,true)) {
//check if any of the cubes get hit by the mouse in either x direction or y direction, it is a hit.
blockArray[i].alpha=.3;
}
}
}
No comments:
Post a Comment