View Full Version : Easing
tranism
September 5th, 2003, 07:16 PM
Peoples, as soon as page finishes loading, I need several movieclips to move from point A to point B with ease out. I've found tutorials for easing but they explain easing for mouse overs, followers, buttons, etc.. I just need the movement with easing as soon as the page loads. Anyone help?
lostinbeta
September 5th, 2003, 07:52 PM
//create prototype function
//x parameter = final _x position
//y parameter = final _y position
//speed parameter = speed to get there (the higher the # the slower the ease)
MovieClip.prototype.easeTo = function(x, y, speed) {
this.onEnterFrame = function() {
//set move to location
this.eX = Math.round(x-this._x);
this.eY = Math.round(y-this._y);
//ease to location
this._x += this.eX/speed;
this._y += this.eY/speed;
//if the eX and eY variables are both equal to 0
if ((this.eX && this.eY) == 0) {
//place the clip at the final destination point
this._x = x;
this._y = y;
//stop running the onEnterFrame
delete this.onEnterFrame;
}
};
};
//ease targetClip to (200, 300) at the speed of 5
targetClip.easeTo(200, 300, 5);
tranism
September 5th, 2003, 07:57 PM
Whoa, hold on there cowbody, panda bar, transformer. etc... Will you be so kind as to explain the lines of code. My brain gets stupid anytime I see x, y and the worth math together.
kode
September 5th, 2003, 08:02 PM
Lost,
This line is wrong:
if ((this.eX && this.eY) == 0)
It should read:
if (this.eX == 0 && this.eY == 0)
// or, if you want to make it shorter:
if (!this.eX && !this.eY)
Senocular explained the whole deal in this (http://www.actionscript.org/forums/showthread.php3?s=&threadid=25931) thread at actionscript.org (http://www.actionscript.org). ;)
lostinbeta
September 5th, 2003, 08:03 PM
The code is pretty straight forward, so the comments are pretty much everything.
The important thing to know here is that easing is the same no matter how you do it. There is an equation that pulls it off, and implementation of that code can be different, but the equation itself is always the same (unless you use Robert Penners easing equations, but if you can't understand mine you definitely aren't going to understand his)
There are 2 easing tutorials here at kirupa that explain the easing equation:
Mouse Follow w/ Easing:
http://www.kirupa.com/developer/mx/followease.htm
Easing on Mouse Click:
http://www.kirupa.com/developer/mx/easing_mouseclick.htm
And for more to understand what is going on here you will have to understand...
Prototypes:
http://www.kirupa.com/developer/actionscript/tricks/prototypes.htm
Variable Scope:
http://www.kirupa.com/developer/actionscript/tricks/scope.htm
Dynamic Event Handlers:
http://www.kirupa.com/developer/actionscript/tricks/dynamicevent.htm
lostinbeta
September 5th, 2003, 08:05 PM
Originally posted by kode
Lost,
This line is wrong:
if ((this.eX && this.eY) == 0)
It should read:
if (this.eX == 0 && this.eY == 0)
// or, if you want to make it shorter:
if (!this.eX && !this.eY)
Senocular explained the whole deal in this (http://www.actionscript.org/forums/showthread.php3?s=&threadid=25931) thread at actionscript.org (http://www.actionscript.org). ;)
Thanks for that kax, I didn't know that.
Well I tested it using trace to find position and trace to run after the if statement and everything seems to work just fine in this case though so I won't consider it <I>completely</I> wrong :sure:
tranism
September 5th, 2003, 08:09 PM
Ah, you're right. I get it. Pretty cool. I have Robert Penner's actionscript book. Funny thing is when I looked at his equations, (well just two of them because he has so many). I sort of understood it. This one just threw me off because I easily get intimidated anytime I see code. Thanks lostinbeta and kode. :)
kode
September 5th, 2003, 08:10 PM
...That's really weird, lost. It makes no sense! :P
And here's my proof!!
var a = 0;
var b = 1;
trace((a && b) == 0);
As you can see, the output is true, although b is not equal to 0. :P
lostinbeta
September 5th, 2003, 08:11 PM
Hmm, weird... perhaps it is just because of the easing equation then :q:
Well anywho, thanks for the tip kax, will definitely come in handy for the future (although I rarely ever used the method I used now and I have no clue why I did now)
tranism
September 5th, 2003, 08:13 PM
Kode, the link you gave to Senocular explaination is the wrong thread.
kode
September 5th, 2003, 08:16 PM
Anytime, lostinpanda. ;)
But once again, I know that thanks to senocular, so you (we!) should be thanking him! :P
Originally posted by tranism
Kode, the link you gave to Senocular explaination is the wrong thread.
Nope, it's not the wrong thread. ;)
lostinbeta
September 5th, 2003, 08:16 PM
No it isn't tranism, senoculars post may not be the first post in there, but the explanation is surely in there (starts 4th post down)
kax: lostinpanda? HAHAHAHA thanks :blush:
tranism
September 5th, 2003, 08:19 PM
I like that. lostinpanda
senocular
September 5th, 2003, 08:22 PM
var a = 0;
var b = 1;
trace((a && b) == 0);
a && b is evaluated as a boolean seperately from the == 0
a and b? ... b yes, b is one, but not a, is is 0 so a && b is false or 0)
then, with that evaluated, therein is the comparison between that result and 0.
(0) equal 0? ... yes, therefore the final if check resovlves to true
so it works when they are both 0, but its also true when any one of them are 0...
anywho, ka... err kode ;) linked the right thread, its just more about || (or) than && (and) but still informative. :)
and both of you turds are browsing invisible :P ;)
lostinbeta
September 5th, 2003, 08:25 PM
Well if it isn't the lostinpanda proclaimed creator of Flash himself.... Senocular.
Very clear description there Sen (as usual)
kode
September 5th, 2003, 08:30 PM
How on earth do you manage to find the words to make everything look so easy, sen!? :P
And we're obviously not invisible to you... :sigh:
lostinbeta
September 5th, 2003, 08:35 PM
Sen is god, that's how... duh kax.
So sen, when you coming to tutor me :beam: :q:
tranism
September 5th, 2003, 08:36 PM
Geez, I'm surround by flash masters. I feel stupid. LOL Well if any of you need help with lightwave, 3d max, maya, combustion or after fx, LET ME KNOW :)
senocular
September 5th, 2003, 08:38 PM
Originally posted by lostinbeta
Sen is god, that's how... duh kax.
So sen, when you coming to tutor me :beam: :q:
oooh yeah... lets wait til FMX 2004 comes out :beam:
kode
September 5th, 2003, 08:39 PM
He's not god... he's got to be something more than that, really. :P
And I'll keep that in mind tranism, thank you. =)
lostinbeta
September 5th, 2003, 08:41 PM
Originally posted by senocular
oooh yeah... lets wait til FMX 2004 comes out :beam:
LOL, well I hope you can bring your copy because there is no way I will be able to afford that, it took me forever to save up for MX and I got a deal on that because my sisters boyfriend (at that time) worked at a computer store that had it!
Although OOP is mainly where I need help in, and if that's going to change... oye.... I am ultra excited about AS 2.0 but at the same time I don't want it to come because then I essentially get bumped back down to "newbie" :(
senocular
September 5th, 2003, 08:46 PM
Ill bring mine... so Ill have to snag myself a laptop too :!: ok Ill work on that. wheeew Im going poor pretty quick :hangover:
lostinbeta
September 5th, 2003, 11:00 PM
Originally posted by senocular
Ill bring mine... so Ill have to snag myself a laptop too :!: ok Ill work on that. wheeew Im going poor pretty quick :hangover:
LOL, well you don't have to get a laptop, you can just bring it here and install it on my computer ;) ;)
:beam:
j/k
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.