Groups | Blog | Home
all groups > flash (macromedia) > february 2007 >

flash (macromedia) : beginner hittest failure


akinebs
2/24/2007 4:01:43 PM
I have 10 instances of a mc (Ball_mc1, Ball_mc2, ...) created at runtime. I
have attached a reference to each instance in a unique array element:
ball_array[1, 2, ...]. In a loop I have code to make the balls wander around
triggered by an onEnterFrame event. I also have code which I hoped would detect
collisions between the balls but it does not. Below is the code I have and line
eight is where I think I am doing something wrong.

1 ball_array = new Array(11)
2 this.createEmptyMovieClip("holderClip", this.getNextHighestDepth());
3 for (var i:Number = 1; i <= 10; i++){
4 ball_array[i]=holderClip.attachMovie("Ball_mc", "Ball_mc" + i,
holderClip.getNextHighestDepth(),
{_x:random(550),
_y:random(400)});
5 ball_array[i].onEnterFrame=function(){
6 Wander around code
7 for (j = 1; j <= 10; j++){

8 if (ball_array[i].hitTest(ball_array[j])){setProperty (ball_array[j],
_alpha, 20);}

9 }//eo sec loop over j
10 }//eo enter frame event
11 }//eo primary loop over i

akinebs
2/24/2007 11:17:16 PM
FOUND SOLUTION:

for (j = 1; j <= 10; j++){ //Begin collision detect code
if (this<>ball_array[j]){
if (ball_array[j].hitTest(this)){setProperty (this, _alpha, 20);}
}//eo this ne ball
}//eo sec loop over j
AddThis Social Bookmark Button