PDA

View Full Version : lesson for noobs - movement via AS (and easing)....


gunko2
09-03-2004, 12:18 PM
hi,
i have seen in this forum that a lot of questions are about moving a mc via AS....
so i decided to maybe start a post about this....
so here goes nothing....
lesson #1:
this is a basic movement - just create a movieclip and put the following actions to it:

onClipEvent (enterFrame) {
this._x = this._x+5;
}

this script moves a mc 5 pixels to the right every time it enters the frame....
if u want it to go to the left just change the "+" to "-".
lesson #2 (i always wanted to say that lol):
if u want to move a mc from point a to point b with an easing:

onClipEvent (load) {
destinationX = 150;
TheSpeedOfTheMovement = 7;
}
onClipEvent (enterFrame) {
this._x = this._x+(destinationX-this._x)/theSpeedOfTheMovement;
}

i"ll explain the code:
now first we decalaired 2 variables....
the first is "destinationX" and we asighned it a value of 150.
now this veriable is actually the x position u want the mc to ease to....
(u could of called the var "myDog" it doesn't matter)
the second one is "theSpeedOfTheMovement" and we asighned it a value of 7.
and that is (yeah that's right u guessed it) the speed of the movement - the higher the number the slower it goes....
now let's go the second part of the code....

this._x = this._x+(destinationX-this._x)/theSpeedOfTheMovement;

now:
every time it enters the frame it calculates the x position of the mc.
for example the "destinationX" equales 150. and the x posiotion of the mc is 250. so it calculates: 250+(150-250)/7 = 236. so now the x position is 237 so now replace 250 to 237 and etc etc. untill it get's to 0. and that's how u get easing.
so that's it for the first part. stay toon for the next part.
if anyone has any suggestions then.... u know.... just say so....
i hope this will help many noobs....
and maybe turn it to a sitcky!
;)