I have this code, and in the end, where I am trying to removeChild(ball) I get an error:
1118: Implicit coercion of a value with static type Object to a possibly unrelated type flash.display:DisplayObject.
for (var i:uint = 0; i < 50; i++) {
var ball:Ball = new Ball();
ball.x = Math.random() *reference_mc.width + reference_mc.x;
ball.y = Math.random() *reference_mc.height + reference_mc.y;
addChild(ball);
ball.addEventListener(Event.ENTER_FRAME, everyFrame);
}
function everyFrame(e:Event):void {
** var ball:Object = e.target;**
var dx:Number = ball.x - parent.mouseX;
var dy:Number = ball.y - parent.mouseY;
var angle = Math.atan2(dy, dx);
var dist:Number = Math.sqrt(dx*dx + dy*dy);
var accel:Number = (range - dist) * accelFactor;
if (accel > 0) {
speed += accel;
}
speed *= decelFactor;
ball.x += speed * Math.cos(angle);
ball.y += speed * Math.sin(angle);
//remove them if they exit screen
if (ball.x - ball.width/2 > stage.stageWidth || ball.x + ball.width/2 < 0 || ball.y - ball.width/2 > stage.stageHeight || ball.y + ball.width/2 < 0) {
**removeChild(ball);**
}
}