Animating with ActionScript 2
January 28th, 2009
Episode 16
Coming up on today’s epsiode:
Find out how to make simple animations in Flash CS4 using Action Script 2.
Right off the bat I make a new layer and I call it actions. It is always best practice to have your actions on its own layer without graphics. So I start every project off by adding an Actions layer and locking it.
On layer one, grab the oval tool make sure that you don’t have a stroke color and draw a circle on the screen. Hold down shift to constrain the proportions. With the object now selected lets hit the hot key F8, this is going to bring up the Convert to Symbol Dialog box.
Make it a movie clip and give it a name of red Ball. Now you should see a movie clip in you library called red Ball. Whatever name you give it if the library doesn’t matter. It’s the instance name that Action Script will be looking for. So select the movie clip and locate your properties panel. In this panel is where you will see a place for an instance name. Lets give it a name of ball. Now select your actions layer and press F9 to get your action panel up.
With our actions panel open the first thing we need to do is import what functionality we want to use. WE want tweens and easing. So go ahead and import them by typing “import mx.transitions.Tween; import mx.transitions.easing.
The import of tweens is finding a folder with premade tween animation script. The same thing can be said about the easing. But notice on the easing I typed a .* this is telling action script that I want to load all of the easing types so I can use them.
Now that we have imported the functionality we can begin animating. To declare a new tween you need to type out new tween open and close (). In side the () flash is expecting 7 parameters.
- The object that you are wanting to target
- What property you want to effect.
- Tween type and easing type.
- Starting location or starting percentage
- Ending location or ending percentage
- Duration
- True if you want the duration to last in seconds or False if you want the duration to last in frame
So lests tackle it. The first parameter is what object I want to effect so I am going to put ball comma. Next is the property, note you have to put this one in quotes, so I want the ball to fall down so quote underscore y quote comma. Here comes the tween and easing type, there are several types of tweens and easing we will cover only one, don’t worry I made a cheat sheet that you can take and reference for all the types, I want it to bounce and have a bit of ease out. If this part didn’t turn blue then you spelled something wrong, this part is very case sensitive.
Next I want to start the balls position from zero. This number will take the ball from where ever it is at and place it at the y coordinate of zero. If you wanted it to start from where it is on the stage then simply type ball._y here. This says were ever the ball is start here. Next is the ending location. Since I used a numeric value in the previos one I will add a numeric value to this one. But lets say I want it to move 200 pixils from where it is at simply type ball._y + 200.
The last two are important to each other , if the last parameter is false then the number will represent a duration in frames. But if the last one is true then the previous number is take place over seconds. So lets add 2 comma true. This says take 2 seconds to play out.Go ahead and test movie and see what happens. You just made action script animate your ball. Don’t forget to grab my cheat sheets and source file at Jermbo.com




