Help! My balls aren’t moving…
“mover” function worked in AS2, but not translating to AS3.
for (var i:Number = 0; i < 10; i++) {
var ball:Ball = new Ball();
ball.x = Math.random()* stage.stageWidth;
ball.y = Math.random()* stage.stageHeight;
ball.dx = Math.round(Math.random()* stage.stageWidth);
ball.dy = Math.round(Math.random()* stage.stageHeight);
ball.alpha = Math.random() * .9 + .5;
ball.scaleX = ball.scaleY = Math.random() * 4.5 + .8;
addChild(ball);
ball.addEventListener(Event.ENTER_FRAME, mover);
}
function mover(e:Event):void {
this.x += (this.dx-this.x)/.2;
this.y += (this.dy-this.y)/.3;
if(Math.round(this.x) == this.dx) {
this.dx = Math.round(Math.random()* stage.stageWidth);
this.dy = Math.round(Math.random()* stage.stageHeight);
}
}
Noob missing something simple?