Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

actionscript run "inertia" behaviour on rollover/rolloff 1

Status
Not open for further replies.

glennchristensen

Technical User
Sep 23, 2003
9
AU
hi guys,

need help with an actionscript run behaviour . on rollover I need the actionscript to move an object ( a mask over an image ) and the reverse on rolloff. This needs to be done using inertia. I know its a simple script (there should be a premade version floating around in cyberspace somewhere) but I'm not sure how to start the syntax or the formula for the math.round equation to create the "pull/inertia" effect.

An example of this can be seen on homepage. this is exactly what I mean.

any help is appreciated

glenn
 
And where eaxctly is this inertia on digitalvision?

Regards,

cubalibre2.gif
 
the flash to the right of the page animates with an "inertia-like" effect. the mask animates fast then slows on rollover of image
 
Sorry but I don't see what you're talking about.

Regards,

cubalibre2.gif
 
ok lets forget about digital vision. It was a crap example - sorry.

what we have is 3 layers in a MC

layer1 - image (simple graphic)
layer2 - white box (MC instance name "box1") of the same size as the graphic at 60% opacity
layer3 - invisible button.

the actionscript behaviour on rollover of inv button needs to make "box1" move completely off the image but with a gravity/inertia kind of movement - fast then slow upon reaching target.

the rolloff from inv button is the reverse - move "box1" back to original position with same effect.

glenn
 
All of those types of transitions use variations on this idea:

"change current position by a fraction of the amount left to the target position"

...so if you wanted to move by half the distance between where your clip currently is and where it needs to go, which provides a dramatic braking effect, your formula would be:

clip._x+=(targetX-clip._x)/2;

...the speed (number you're dividing with) can be any value greater than one, the lower it is the more noticeable the deceleration is, the higher the number the smoother the overall effect.

Since we're dealing with pixels you'll need to put a condition in there which stops calling the formula when the difference between the clip and its target pos is less than one or else it just keeps dividing by invisible amounts wasting processor cycles and slowing your movie.
 
sorry, I am a bit confused

if this formula is on a button

on (rollover); {
clip._x+=(targetX-clip._x)/2;
}

where and how do we define the targetX?
 
TargetX is where you want the object with inertia to end up.

(I would have used a variable to store the current velocity, but I guess that comes from spending too much time making arcade-style games.)
 
You wouldn't normally put the code on the button itself as the script has to run over several frames to work.

Something like this would be better:

Code:
function doInertiaMove(targetX) {
	//set up the move, updated every frame
	this.onEnterFrame = function() {
		clip._x += (targetX-clip._x)/2;
		if (Math.abs(targetX-clip._x)<.1) {
			//clear the move when the clip is in position
			this.onEnterFrame = null;
		
		}
	};
}
button.onRollOver = function() {
	//call the function that does the move with a parameter which becomes 'targetX'
	doInertiaMove(300);
};
 
schmick!
thats excellent.
thanks guys

so to inverse it on rollOut...

button.onRollOut = function() {
    //inverse action
    doInertiaMove(original location #);
};

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top