I have an MC that uses actionscript movement with easing… My question is how do I get the MC to move again after the first _x and _y coordinates are reached?
onClipEvent (enterFrame) {
var dx = endX-_x ;
var dy = endY-_y ;
_x += dx / speed;
_y += dy / speed;
if ( Math.abs (dx) + Math.abs (dy) < 1 ) {
endX = 200 ;
endY = 150 ;
}
}[/AS]You could also use an array if there are more than 2 positions.
It would be better with dynamic event handlers but here it goes:[AS]onClipEvent (load) {
_x = 0;
_y = 0;
speed = 5;
myDestinations = [{x:400,y:300},{x:40,y:350},{x:120,y:90}];
index = 0 ;
}
onClipEvent (enterFrame) {
var endX = myDestinations[index].x ;
var endY = myDestinations[index].y
var dx = endX-_x ;
var dy = endY-_y ;
_x += dx / speed;
_y += dy / speed;
if ( Math.abs (dx) + Math.abs (dy) < 1 ) {
index ++ ;
index = index % myDestinations.length ;
// that way, when you reach the last item of the array, you
// go back to the first item
}
}[/AS]