ActionScript for Designers Part 1- Basics of ActionScript

Hi Guys,

Generally Flash comes with two meanings – 1) Flash for Designer & 2) Flash for Developers (ActionScript). Designer always threaten about ActionScripting. It is not that complicated at basic level where Designer can levarage the benefits of ActionScripting to their Creative Work without having Programming knowledge.

If you already know the Flash, using tools and creating animations, you may want to add some interactivity to your skills.

Actionscript is written as a series of statements within a Flash movie, and is placed either in a frame or in an external class file. In the Flash intro class, we also put actionscript on buttons and movieclips, but that was done for the sake of easier learning.

ActionScript, an object oriented programming (OOP) language built for Flash/Flex developement. There are versions of actionscript like Flash (7/8/ cs2 etc..), these are ActionScript 1.0, 1.1, 2.0, 3.0.  Based on the Flash version, adobe provides default scripting version which is located at Publish Settings in Flash IDE (Integrated Development Environment).

 1. TRACE

Trace function 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 for debugging, 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”);

2. FUNCTIONS

Functions are basically reusable chunks of code that you don’t want to rewrite over and over again.  It saves your coding time and add scalability layer to your code.

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

3. TIMELINES

Flash Timeline refers to the sequence of frames and keyframes in either a movieclip or on the Stage or main movie. The stage’s timeline can be treated in actionscript as an instance of a movieclip. It is represented either as _root (from any timeline in the movie which is deeply nested to N-level), or as _parent from a movieclip placed on main timeline frames. It is often referred to as the main timeline.

 

5. PLAYHEAD CONTROL

Using simple playhead control, you can take control of your timeline. A lot of animations you can place on timeline which can be easily played using playhead functions. These include:

gotoAndStop(frameVariable);
gotoAndPlay (frameVariable);
stop();
 
 
 6. ASSIGNING ATTRIBUTES

  

Assigning attributes allows you to dynamically store or update items in your variables(Container) using Actionscript. This includes visibily, scale, alpha, position etc… Some examples:

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

7. IF STATEMENTS

 
if statements are used to take decisions inside code. It is straightforward.
if (myVariable==myOtherVariable)
{
trace(myVariable);
}
for e.g.
if(mc_MyMovieCliep._alpha==50)
{
   trace(“Alpha is 50”);
   //do something
}
else
{
 //do alternative
}

8. FOR LOOP & WHILE LOOP


Loops are used to perform specific tasks to certain number of times or until a condition satifies. There are two kind of loops – FOR loop, & WHILE loop.
for (var startCounter=0; startCounter<5; startCounter++)
{
trace(startCounter);
}

var startCounter=0;
while (startCounter != 10)
{
trace(“Count “+ startCounter);
startCounter++;
}

9. BUTTONS

Buttons can be used to control movies. To accomplish this, you need to attach action to the button or movie clip with the on() function. You could write actions in the Timeline using event handler functions with instance names of button or movie clips or you can write actions on button or movie clips, for this you need to select button or movie clip and Press F9 to open Action window.
on(release)
{
 mc_myMovieClip._visible=false;
}

 

Hope you like this tutorials. I am working on it to proceed further with more detailed one.

Happy Coding 🙂