so i bought this code (im an noob) so i could do this layered movement illusion, and I applied this code to one of the layers that has a looping movie with a motion guide, and every time it restarts its loop, the object moves 5 pixes or so away from the mouse. It gets quite annoying, and eventually it moves itself off the stage of my swf; to the point where i can no longer use the movie clip which i rely on for navigation
I have a feeling it has to do with the onEnterFrame
Is there any way to modify the code so it wont do that anymore?
Here is the code below:
Code:
//Set limits of image motion (note that negative values will change direction of image motion):
var y_limit:Number = 60;
var x_limit:Number = 90;
//Set speed of motion (large numbers = slower speed, if this is set to 1, motion will be instantaneous)
//DO NOT SET TO A VALUE LESS THAN 1.
var speed:Number = 15;
//THE FOLLOWING DOES NOT NEED TO BE MODIFIED:
//get original position:
var origx = this._x;
var origy = this._y;
onEnterFrame = function(){
//calculate goal coordinates based on mouse position:
goalx = origx - (((_parent._xmouse-Stage.width/2)*x_limit) / (Stage.width / 2));
goaly = origy - (((_parent._ymouse-Stage.height/2)*y_limit) / (Stage.height / 2));
//adjust position of image gradually:
this._x += (goalx - this._x)/speed;
this._y += (goaly - this._y)/speed;
}