ActionScript
Frame Script
Frame ActionScript is executed when the frame is about to appear.
To define the script choose "Frame" > "ActionScript" command and enter the script in the dialog.
Button Scripts
ActionScript can be executed on button events (OnClick, OnUp, OnOver, OnOut etc).
To define an event script select the item and choose
"Action" and "On Click", "On Out", "On Over", "On Up" commands. Select "ActionScript" option and enter the script.
To create edit fields
Use edit fields to allow interaction between the user and the movie.
To draw an edit choose the
tool and draw it on the frame.
The field will appear as "Edit1", "Edit2" etc.
To test the ActionScript
Draw an edit field that will appear as "Edit1" (or Edit2 etc). Choose "Frame" > "ActionScript" and paste the code:
Edit1 = "hello there";
Hit F9 to execute the script.
To test the ActionScript for a button click
Draw an edit field that will appear as "Edit1" (or Edit2 etc). Draw a button. Select the button and choose "Action" > "On Click". Select "ActionScript" and paste the code:
Edit1 = "hello there";
Hit F9 and click the button to execute the script.
To enable the item for the script
To access item properties like _rotation in your script you have to export it as "ActionScript Target". Choose "Item" > "Placement Properties" and check "ActionScript Target". Flash Designer defines the following items as ActionScript targets:
- Sprites
- Groups
- Items defined as sprite animation (with command "Animation" > "Loop Animation")
Script example:
Sprite1._rotation = 90;
Note: The sprite will be rotated by the top left edge (coordinate 0,0). Move sprite items over the top left edge of the sprite to rotate the item by its center point.
To show or to hide an item
Use:
youritem._visible = false; to hide the item and youritem._visible = true; to show the item
Movie Control
stop();
Stops the movie.
play();
Starts the movie.
nextFrame();
Goes to next frame.
prevFrame();
Goes to previous frame.
NOTE: Because Flash Designer is using 2 physical frames for each frame use nextFrame and prevFrame twice. For example:
prevFrame();prevFrame();
gotoAndPlay("Frame 2");
Jumps to "Frame 2" starts playing the movie.
gotoAndStop("Frame 2");
Jumps to "Frame 2" and stops the movie.
_parent.gotoAndStop("Frame 2");
Scrolls the parent movie to the frame labeled "Frame 2"
Sprite2.gotoAndStop("Frame 2");
Scrolls Sprite2 to the frame labeled "Frame 2"
_root.gotoAndStop("Frame 2");
Scrolls the main movie to the frame labeled "Frame 2"
stopAllSounds();
Stops all non-streaming sounds in the movie.
getURL(url,target);
Jumps to a web page.
Example:
getURL("http://www.selteco.com","_blank");
Flash Player Version
ActionScript is in the beta phase. Not all commands are supported.
If you use action script we suggest to set Flash Player version to 6.
Choose "Movie" > "Export Options" and change Target Player to Flash Player 6
Parameters
You can pass parameters to your Flash movie in the query string, for example
PARAM NAME="MOVIE" VALUE="myflashfile.swf?param1=3¶m2=john"
To specify parameters choose "Movie" > "Export Options" and enter parameters in "Parameters" field.
Operators
+ | Add |
- | Subtract |
* | Multiply |
/ | Divide |
== | Equal |
Control Flow
if (expression) { } else { };
Example:
if (x==9) gotoAndStop("Frame 2"); else gotoAndStop("Frame 3");
while(expression) { };
Example:
while(x<10) { x++; }
for(init;expression;increment) { };
Example:
for(x=0;x<10;x++) { }
*break and continue is not supported in for and while
Macromedia ActionScript Reference (PDF 6MB)
download.macromedia.com/pub/documentation/en/flash/mx2004/fl_actionscript_reference.pdf
Built-in classes
Core Classes
Arguments
Array
Boolean
Button
Date
Error
Function
Math
Number
Object
String
Flash Player Classes
Accessibility
Button
Color
ContextMenu
ContextMenuItem
Key
LocalConnection
Mouse
MovieClip
MovieClipLoader
PrintJob
Selection
Stage
System
TextField
TextFormat
Media Classes
Camera
Microphone
NetConnection
NetStream
Sound
Video