# AS3 Random Motion

**URL:** <https://forum.kirupa.com/t/as3-random-motion/270669>\
**Category:** flash\
**Created:** [September 12, 2008, 6:35am UTC](https://forum.kirupa.com/t/as3-random-motion/270669 "2008-09-12T06:35:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bimyou](https://avatars.discourse-cdn.com/v4/letter/b/b5e925/32.png) [@bimyou](https://forum.kirupa.com/u/bimyou)\
**Post date:** [September 12, 2008, 6:35am UTC](https://forum.kirupa.com/t/as3-random-motion/270669/1 "2008-09-12T06:35:14Z")

</div>

Help! My balls aren’t moving…  
“mover” function worked in AS2, but not translating to AS3.

```auto

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?
