Okay, so I have a function on the Main Timeline that creates an instance of the class Ball once every 60 frames (1 second). In the class code for Ball I have this:
package {
import flash.display.MovieClip;
import flash.events.*;
public class Ball extends MovieClip {
private var _root:Object;
private var distY:Number;
public function Ball() {
addEventListener(Event.ADDED_TO_STAGE, beginClass);
}
private function beginClass(event:Event):void {
_root=MovieClip(root);
addEventListener(Event.ENTER_FRAME, eFrame);
}
private function eFrame(event:Event):void {
this.y+=1;
for (var i:int=0; i<_root.numBalls; i++) {
var mc:Ball=Ball(getChildAt(i));
for (var j:int=0; j <_root.numBalls; j++) {
var mc2:Ball=Ball(getChildAt(j));
distY=Math.abs(this.y-_root.getChildByName("Ball"+i).y);
if (distY<=this.height) {
trace("STOP");
}
}
}
}
}
}
As you can see, I am trying to make it so that if two instances of the class Ball collide, then it should output “STOP”. But it isn’t working. Can anyone please tell me what I am doing wrong?