Flash Actionscript Cheat Sheeet

ADVERTISEMENT

Flash ActionScript
setInterval, clearInterval
Program Flow Control
Repeatly execute a function (or an object).
if (condition){
if (age>=18) {
Quick Reference
statement(s);
trace("welcome, user");
\\========= Example=========
Author: Jialong He
} else {
}
var intervalId:Number;
else {
statement(s);
var count:Number = 0;
}
trace("sorry, junior");
var maxCount:Number = 10;
}
var duration:Number = 20;
Introduction
for (init; condition; next) {
for (Cnt = 1; Cnt<10; Cnt++) {
function myCallback():Void {
statement(s);
trace(Cnt);
Using Flash to create animations on the web is popular because the flash
trace(count);
}
}
player is installed on most computers and the published flash file (SWF
if(count >= maxCount) {clearInterval(intervalId);}
file) is small. Flash has a powerful scripting language called ActionScript.
count++;
switch (expression){
Switch (myChar) {
You can use write script to manipulate and control objects on the stage. Its
}
caseClause:
case "A" :
syntax is similar to JavaScript (or C++).
intervalId = setInterval(this, "myCallback", duration);
[defaultClause:]
case "a" :
trace("you pressed A or a");
}
Note: this quick reference is based on ActionScript 2.0 language reference.
escape, unescape
Converts the parameter to a string and
break;
Script Example
encodes it in a URL-encoded format, where
default :
all nonalphanumeric characters are replaced
trace("you did not press A");
A script can be associated with a keyframe or with an object. To test the
with % hexadecimal sequences (e.g, @ to
}
following script, copy it to the action panel. Press “Ctrl + Enter” to start the
%40).
for (var in object) {
var myObject:Object = {Name:"Tara",
flash file.
getProperty, setProperty
Get (set) movie clip property
statement(s);
age:27, city:"San Francisco"};
}
//====================
for (var prop in myObject) {
Load a web page in browser
// A simple ActionScript
getURL
trace(myObject[prop]);
//====================
Mouse/ket event handler
on (event) {
}
for (Cnt=1; Cnt<10; Cnt++) {
Press, release, releaseOutside, rollOut,
trace(Math.random());
var Cnt:Number = 0;
while(condition) {
}
rollOver, dragOut, dragOver, keyPress
}
statement(s);
while (Cnt < 20) {
trace ("Hello, World!");
}
trace(Cnt);
e.g.; on (press) { startDrag(this); }
i += 3;
Movie clip event handler. load, unload,
onClipEvent(movieEvent:
}
Object) {
enterFrame, mouseMove, MouseDown,
Operator
var myVar:Number = 0;
do { statement(s) } while
statements;
MouseUp, KeyDown, KeyUp, Data.
(condition)
do {
}
+, -, *, /, %
Add, Subtract, Multiply, Division, Remainder
trace(myVar);
onClipEvent (keyDown) {
Combine with assignment operator
+=, -=, *=, =/, =%
myVar++;
if (Key.getCode() == Key.RIGHT) {
Increase, decrease, Array access
++, --, []
} while (myVar < 5);
this._parent.nextFrame();
==, !=, <, <=, >, >=
Comparison, equal, not equal, less than, …
} else if (Key.getCode() == Key.LEFT) {
function mySquared(x:Number) {
function FName(P){
this._parent.prevFrame();
!, &&, ||
Logical NOT, AND, OR
statement(s)
return Math.pow(x, 2);
}
}
}
<<, >>, >>>
Bit shift, left, right, right unsigned
}
class, interface, implement,
Define custom class related statements
~, &, |, ^
Bitwise NOT, AND, OR, XOR
startDrag, stopDrag
Makes the target movie clip draggable while
dynamic, extend, private,
new, delete
Allocate (delete) an object
the movie plays.
public, intrinsic
typeof, instanceof
get expression type, test an instance
my_mc.onPress = function () {
//, /* */
One line and multiple line comments
startDrag(this);
Global Functions
}
my_mc.onRelease = function() {
play, stop, nextFrame, prevFrame
Main timeline movie clip play head
Constants and Compiler Directives
control
stopDrag();
gotoAndPlay, gotoAndStop
}
nextScene, prevScene
true, false, undefined,
Predefined constants
fscommand
Lets the SWF file communicate with either
null, NaN, Infinity
loadMovie, loadMovieNum
Loads (unload) a SWF, JPEG, GIF,
Flash Player or the program that is hosting
newline
unloadMovie, unloadMovieNum
or PNG file from local disk or web
Flash Player, such as a web browser.
server into a movie clip
#initclip
Initialization actions are executed only once
when a SWF file is played
loadVariables, loadVariablesNum
Reads data from an external file
statements(s)
e.g, fscommand("fullscreen", true);
either on local disk or on web server
#endinitclip
isFinite, isNaN
Test number
#include “filename.as"
Include external ActionScript

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go
Page of 3