Sunday, May 16, 2010

Flash Animation Actionscript - Top 10 Basic Codes Needed

Here's a list of the 10 most useful codes you can use in any Flash version. These are essential for creating Websites, Games, or interactive animations. Actionscript can go under multiple places. (T) means that this code would be put under the Actions of a frame in the Timeline. (M) means this code would go on the Actions of a MovieClip.

1. stop(); (T) Most useful code and most basic. It will stop an animation on whatever frame the code is put on. If I am making a game or opening screen to a movie, this is a must.

2. play(); (T) The opposite the the last code. Put under the timeline to start the animation back up.

3. gotoAndPlay(); (T) This code is much more useful and more common than the last and allows you to tell the animation to skip to a certain frame of the animation. Essential for games. The number of the frame you want to go to is put inside the parenthesis in it. For example gotoAndPlay(10);

4. gotoAndStop(); (T) This code skips to a certain frame of the animation, but then stops at that frame. Essential for games. The number of the frame you want to go to is put inside the parenthesis in it. For example gotoAndPlay(10);

5. on(Release){ } (M) This code turns any movieclip have the same functionality of a button, meaning that you don't ever have to worry about ever creating Buttons. Any actions you want the button to do after clicking on it is placed inside the brackets. I have this code on ever link or button on my website. Its helpful to make a box with 0 alpha inside the movieclip to serve as a hit area for the button.

6. on(rollOver){ } (M) Similar to the above code. Except instead of making an action happen once you click on a button, it happens when the mouse rolls over it. Its helpful to make a box with 0 alpha inside the movieclip to serve as a hit area for the button.

7. on(rollOut){ } (M) Same thing as above but this makes an action happen when you roll your mouse off the button.

8. ifFrameLoaded ("end") { (T) A little bit more complicated here. This code is all you need to make a

gotoAndPlay ("start"); preloader work. You just name the last frame in an animation "end" and
} the second frame "start". Put this code on the first frame with a little loading animation to make it more interesting. The code means that if the last frame has loaded (aka "end") then its ok to go to and play the first frame called "start".

9. if( ){ } (T) or (M) The if statement is essential for harder programming. It means that if "a" happens then make flash do "b". The "a" part goes in the parenthesis and the "b" part goes in the brackets. An example would be if(section == 1){ gotoAndPlay(10); } which means that the movie would go to frame 10 only if the variable section (defined earlier) was set equal to 1. It is important to note that doubls =s are needed instead of one = when used in the parenthesis of an if statement

10. _root. and this. (T) or (M) These two codes go in front of many other statements in certain important situations. _root. is needed if you're refering to the main movie timeline. And this. is needed if your reffering to the movieclip that you're putting the code on. So if you want the animation inside of a movieclip to go to a certain frame inside it then you would write this.gotoAndPlay(2); If you want the main movie to change alpha for example then you'd write _root.alpha = 50;

There you go. Those are the top 10 most essential codes for Flash Animation needed for interactivity.

No comments:

Post a Comment