Hi all.
I’m working on a little project in which some movieclips are to move random between certain X and Y values. Basically Ive just tried to make this into AS3 code.
This is what it looks like:
this.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
var acceleration:Number = 10;
var ranx:Number = (Math.round(Math.random()*358))+59;
var rany:Number = (Math.round(Math.random()*72))+64;
function newpos():void
{
trace("newpos");
ranx = (Math.round(Math.random()*358))+59;
rany = (Math.round(Math.random()*72))+64;
}
function enterFrameHandler(event:Event)
{
this.x += ((ranx-this.x)/acceleration);
this.y += ((rany-this.y)/acceleration);
if (Math.round(this.x) == ranx || Math.round(this.y) == rany)
{
newpos();
}
}
My problem, then, is this: I need to change the acceleration var to get the movieclip to move slower. However, when i set it to 12 og higher the movieclip will only generate 3 or 4 new coordinates, and then stop completely.
Does anyone know why this is?
Ive attached my .fla so you all can see for yourselves. The code is in the first frame the movieclips timeline.
I hope you can all help as im pretty new to actionscripting.
Thanks,
Esben