autonomously moving movieclip
I'm making an HTML5 document with javascript - and I'm not the best coder. I want to include code in a movieclip that will make it move randomly around the stage, separate from what is going on in my main timeline. I've done this before in Edge Animate (see this) but the same code doesn't work. What I've tried so far is to open the timeline of the Movieclip and add this code in Actions:
var randX; //new position
var randY;
var timeX;
var oldX = 0; //starting position
var oldY = 0;
//chooses a new posiiton to go randomly
function randomNumbersX (){
randX = Math.floor(Math.random()*589);//scaled to the size of the screen
randY = Math.floor(Math.random()*120);
constantSpeedX();
moveMeX();
}
randomNumbersX();
//scales time factor so the speed is the same no matter the distance moved
function constantSpeedX (){
var left = oldX;
var top = oldY;
var a = left - randX;
var b = top - randY;
var c = Math.floor(Math.sqrt((a*a)+(b*b)));
var percentOf = c/600;
timeX = Math.floor(2000 * percentOf);
}
// move the object to the new position
function moveMeX()
{ this.animate([{transform: 'translate(oldX,oldY)'},{transform: 'translate(randX,randY)'}],
{duration: timeX});
oldXX = randXX;
oldYX = randYX;
}
Help!!!!
