# Random motion actionscript errors. Please help!

**URL:** <https://forum.kirupa.com/t/random-motion-actionscript-errors-please-help/198863>\
**Category:** flash\
**Created:** [August 29, 2006, 6:58am UTC](https://forum.kirupa.com/t/random-motion-actionscript-errors-please-help/198863 "2006-08-29T06:58:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ssingru](https://avatars.discourse-cdn.com/v4/letter/s/e8c25b/32.png) [@ssingru](https://forum.kirupa.com/u/ssingru)\
**Post date:** [August 29, 2006, 6:58am UTC](https://forum.kirupa.com/t/random-motion-actionscript-errors-please-help/198863/1 "2006-08-29T06:58:34Z")

</div>

I am trying to generate random motion in flash and can’t seem to make it work.  
Any help will be much appreciated

newpos = function () {  
ranx = Math.random ()\*250);  
rany = Math.random ()\*250);  
}

this.onEnterFrame = function() {  
newpos ()  
this.\_x = ranx;  
this.\_y = rany;  
}

acceleration = 10  
newpos = function () {  
ranx = Math.round((Math.random ()\*250));  
rany = Math.round ((Math.random ()\*250));  
}  
newpos();  
this.onEnterFrame = function() {  
this.\_x += ((ranx-this.\_x)/ acceleration);  
this.\_y += ((rany-this.\_y)/ acceleration);  
};

acceleration = 10  
newpos = function () {  
ranx = Math.round((Math.random ()\*250));  
rany = Math.round ((Math.random ()\*250));  
}  
newpos();  
this.onEnterFrame = function() {  
this.\_x += ((ranx-this.\_x)/acceleration);  
this.\_y += ((rany-this.\_y)/acceleration);  
if (Math.round(this.\_x) == ranx || Math.round(this.\_y) == rany) {  
newpos();  
}  
};
