# Animate a movieclip to random locations on stage

so basically, here’s what i’m trying to do…
supposing there is a movieclip in stage… let’s say its a circle with an instance name of “theCircle”…

the circle has to move / go to / animate to a random location on stage every 5 seconds… basically, the circle should move to the random location, stop and wait for 5 seconds, then move again to another random location… again and again…

the code below is untested and incomplete… but it is what i am trying to do… please give me your suggestions on how i should go about this…

``````var randomXPosition:int;
var randomYPosition:int;
var positionTimer:Timer;
var theCircle:MovieClip

initGame();

function initGame():void
{
randomXPosition = Math.round(Math.random() * stage.stageWidth);
randomYPosition = Math.round(Math.random() * stage.stageHeight);

}

function moveCircle(event:Event):void
{
/* need to put a code here to move the circle with instance name "theCircle"
to the randomXPosition & randomYPosition at a constant speed */

/* once the circle's X position is equal to randomXposition,
and once the circle's Y position is equal to randomYposition,
start the timer... */

startTheTimer();
}

function startTheTimer():void
{
positionTimer = new Timer(5000, 1);
positionTimer.start();
}

function setPositionValues(event:TimerEvent):void
{
positionTimer.removeEventListener(TimerEvent.TIMER, setPositionValues);
randomXPosition = Math.round(Math.random() * stage.stageWidth);
randomYPosition = Math.round(Math.random() * stage.stageHeight);
}
``````

on the moveCircle function, i can simply set the X and Y of the circle equal to randomXPosition and randomYPosition… but that would just change the location of the circle, not move it… i am trying to make the circle animate towards that location at a constant speed…