Patrick Burt - A Blog for Web People

Basic Actionscript Code Beginners Need To Know

Wednesday, December 12th, 2007

Categories: Adobe Flash

RSS Comment Feed

Trackback

AddThis Social Bookmark Button

I was there. I was a designer who had to start using Adobe Flash. Since I was a designer, I had more of a creative side then a logical side which meant learning to code Actionscript was a whole other ballgame. If you’re like me, here’s some easy Actionscript code you should know to get the most out of your Flash work.

Trace

What trace does is it allows you to print information to your output window in Flash. This is not visible to those who view the SWF on the web. Trace is especially useful if something goes wrong and you want to figure out why. You can trace simple text or the contents of variables.

trace(”Text or variables can go here”);

Playhead Control

Using simple playhead control, you can take care of a lot animations that you see on the web. These include:

gotoAndStop(frameVariable);
gotoAndPlay(frameVariable);
stop();

Functions

Functions are basically chunks of code that you don’t want to have to rewrite over and over again. It saves you time writing and updating it. Once your Actionscript skills get more advanced, you’ll be thankful you know how to do functions.

function functionName(inputValue) {trace(inputValue);}

If Statement

Like functions, if statements are a staple of any code. They’re pretty basic and pretty straightforward.

if (myVariable==myOtherVariable) {trace(myVariable);}

Assigning Attributes

Assigning attributes allows you to dynamically place or alter items on your canvas using Actionscript. This includes, but is not limited to visibily, scale, alpha and position. Some examples:

myMovieClip_mc._visible=false;
myMovieClip_mc. _alpha=35;
myMovieClip_mc._x=50;
myMovieClip_mc._y=50;

For Loop and While Loop

These loops facilitate doing tasks specific numbers of times or until a factor has been met. These code bits are fairly straight-forward.

for (var startCounter=0; startCounter<50; startCounter++){trace(startCounter);}

startCounter=0;
while (startCounter != 10) {startCounter++;}

Button Manipulation

If you’ve gotten past the stage where single frame rollovers are passé. These basic commands (when applied to a button) will give you a lot more flexibility then you once thought you had.

on (rollOver) {button_mc.gotoAndPlay(2);}
on (rollOut,dragOut) { button_mc.gotoAndStop(1);}
on (release) {myAwesomeAnimation.gotoAndPlay(2);}

Hope that helps. :)

Bookmark this blog using any bookmark manager!


Related Posts


Subscribe to this Post

Leave a Reply