
Page 2 of 2
Billy T.
This user is yet to take control of their account and provide a biography. If you are the author of this article, please contact us via support AT actionscript DOT org.
View all articles by Billy T.OK now lets control our clip from a button. Remove all the actions on our clip and give it an instance name of "ball". Draw a rectangle on the stage and convert it to a button. Give your button this action -
on (release) {
_root.ball._xscale = random(500);
_root.ball._yscale = random(500);
_root.ball._x = random(500);
_root.ball._y = random(400);
_root.ball._alpha = random(100);
}
Test your movie and click on the button a few times. OK now lets make the clip scroll to different positions.
Give your ball clip this action -
onClipEvent (load) {
//this sets the initial target x position for our clip
_root.targX = 50;
}
onClipEvent (enterFrame) {
//this variable stores the current x position of the clip
cX = this._x;
//this variable stores the distance between the clips current x position
//and where we want it to go
//I am setting the targX variable in the root so that it is easy to target with our button
difX = cX-_root.targX;
//this moves the clip 1/5 of the distance every frame.
//Because the difference between the clips current location and its destination
//will get smaller each frame, so will the amount the clip travels each frame.
//This is what makes the clip appear as though it "eases into" it's final destination
setProperty(this, _x, cX-(difX/5));
//check the flash manual to learn more about the setProperty action
}
and your button this action -
on (release) {
//this sets the targX variable to a random number between 0 and 500
_root.targX = random(500);
}
Test your movie and click the button a few times. Pretty cool huh? You can use this formula on the movieclip to get some great effects. Try (without cheating) adapting it to effect the clips x and y scale. You should end up with something like this on the clip -
onClipEvent (load) {
_root.targXscale = 50;
_root.targYscale = 200;
}
onClipEvent (enterFrame) {
cXscale = this._xscale;
cYscale = this._yscale;
difXscale = cXscale-_root.targXscale;
difYscale = cYscale-_root.targYscale;
setProperty(this, _xscale, cXscale-(difXscale/5));
setProperty(this, _yscale, cYscale-(difYscale/5));
}
and this on the button -
on (release) {
_root.targXscale = random(500);
_root.targYscale = random(500);
}
Test your movie. You will notice that even if you click the button quickly the scaling of the clip never jumps - imagine trying to do that will tweened animation!
OK that's it. Have fun - experiment with it.
You can download the source file for this tute here (not that you will need it...)
cheersSpread The Word
Related Articles
6 Responses to "Basic Animation Via ActionScript" 
|
said this on 17 Apr 2010 10:53:34 AM CST
easy and clear, thanks!
|
|
said this on 24 Oct 2010 3:01:01 PM CST
yes it was very easy to g
ps i |


Author/Admin)
