Appendix D. ActionScript Quick Reference

I l @ ve RuBoard

This appendix is a condensed reference for some of the ActionScript you used in this book. It is organized in alphabetical order, starting with operators. For a complete ActionScript reference, choose Help > ActionScript Dictionary from Macromedia Flash.

Name Syntax and Description Examples
“ “ (decrement)
 --expression expression-- 

Subtracts 1 from the expression. The pre-decrement form ( --expression ) subtracts 1 from expression and returns the result. The post-decrement form subtracts 1 from the expression and returns the initial value of the expression.

--myVar;
“ (subtraction and negation)
 -expression1 expression1-expression2 

Used for subtraction and negation. If used for negation, it reverses the sign of the expression. If used for subtraction, it finds the difference between the two numbers

 x = 5; y = 4: trace(-x); trace(x-y); 

The Output window would display “5 , then 1 .

!= (inequality)

expression1 != expression2

Tests for inequality. If expression1 is not equal to expression2 , the result is true .

1 != 2 returns true .
#include

#include "filename.as"

Includes the contents of the file specified in the argument

#include "style.as"
&& (logical AND)

expression1 && expression2

Performs a Boolean (true or false) operation on both expressions. Both expression1 and expression2 must be true for the operator to return a final result of true .

 x = 10; y = 20; if ((x == 10) && (y == 20)) {   trace ("ZooMX is great!"); } 

The Output window would display: ZooMX is great!

* (multiplication)

expression1*expression2

Multiplies two numbers.

trace (2*4);

The Output window would display 8 .

. (dot operator)
 object.property object.method instancename.variable instancename.child.variable 

Used to navigate movie-clip hierarchies to access nested movie clips, variables , or properties. The dot operator is also used to retrieve or set the properties of an object, execute a method of an object, or create a data structure.

The following identifies the color property of the animal object:

animal.color

/ (division)

expression1/expression2

Divides expression1 by expression2 .

trace (21/3);

The Output window would display 7 .

//

/* */ (comment delimiters)

 // comment here /* comment here */ 

Inserts a comment into your code that is ignored by the ActionScript interpreter.

 /* set value of the variable called common */ common = "Bactrian Camel"; 
_alpha
 instancename._alpha instancename._alpha = value; 

Sets or gets the alpha transparency (0 is fully transparent, 100 fully opaque ).

mPiece._alpha = 50;

Sets the alpha property of the movie clip called mPiece to 50% .

_height
 instancename._height instancename._height = value; 

Sets or retrieves the height of the space occupied by the movie clip.

this._height = 200;
_level

_levelN

A reference to the root movie timeline of levelN . N is an integer specifying depth level (default 0). You must load movies using the loadMovie action before targeting them using _level property.

_level2.gotoAndStop("rf");
_name
 instancename._name instancename._name = value; 

Specifies the movie-clip instance name.

trace(this._name);
_root
 _root _root.movieClip _root.method 

Specifies or returns a reference to the root movie timeline.

 _root.mc1 _root.gotoAndStop(4); 
_visible
 instanceName._visible instanceName._visible = Boolean 

Determines whether or not the movie specified by the instanceName is visible.

mPiece._visible = false;
_width
 instancename._width instancename._width = value; 

Sets or retrieves the width of the space occupied by the movie clip.

this._width = 300;
_x
 instanceName._x instanceName._x = integer; 

Sets or retrieves the x -coordinate relative to the parent timeline.

mPiece._x = 10;
_y
 instanceName._y instanceName._y = integer 

Sets or retrieves the y -coordinate relative to the parent timeline.

mPiece._y = 10;
(logical OR)

expression1 && expression2

Performs a Boolean (true or false) operation on both expressions. The operator will return a final result of true if either expression1 or expression2 is true.

 x = 10; y = 20; if ((x == 10)  (y == 10)) {   trace ("ZooMX is great!"); } 

The Output window would display:

ZooMX is great!

" " (string delimiter )

"text"

When used before and after a string, quotes indicate that the string is a literal, not a variable, numerical value, or other ActionScript element.

obj = "image" + i;
+ (addition)

expression1 + expression2

Adds numeric expressions and concatenates strings. If one expression is a string, all other expressions are converted to strings and concatenated . If both expressions are integers, the sum is an integer; if either or both expressions are floating-point numbers, the sum is a floating-point number.

Example 1 :

trace(1+2);

The Output window would display 3 .

Example 2 :

When myVar = "lion" , the following expression returns "Oh no! It's a lion!":

trace("Oh no! It's a " +myVar+"!");

++ (increment)
 ++expression expression++ 

Adds 1 to the expression. The pre-increment form ( ++expression ) adds 1 to the expression and returns the result. The post-increment form adds 1 to the expression and returns the initial value of the expression.

++myVar;
+= (addition and assignment)

expression1 += expression2

Assigns expression1 the value of expression1 + expression2 .

x += y is equivalent to x = x+y

Example 1 :

 x = 5; x += 10; trace (x); 

The Output window would display 15 .

Example 2 :

 x = "I am afraid of"; x+=" lions!"; trace(x); 

The Output window would display:

I am afraid of lions!

< (less than)

expression1 < expression2

Compares two expressions and determines whether expression1 is less than expression2 .

1 < 2 returns true .
<= (less than or equal to)

expression1 <= expression2

Compares two expressions to determine if expression1 is less than or equal to expression2 in value.

4 <= 4 returns true .

5 <= 3 returns false .

= (assignment)

expression1 = expression2

Assigns the type of expression2 to the variable, array element, or property in expression1 .

latin1 = "Pongo pygmaeus";
== (equality)

expression1 == expression2

Tests two expressions for equality. If expression1 is equal to expression2 , the result is true .

When myVar = "lion" , the following expression returns true:

myVar == "lion"

> (greater than)

expression1 > expression2

Compares two expressions to determine if expression1 is greater in value than expression2 .

300 > 900 returns false
>= (greater than or equal to)

expression1 >= expression2

Compares two expressions to determine if expression1 is greater than or equal to expression2 .

8 >= 5 returns true

30 >= 30 returns true

Array.length

myArray.length;

Property of the Array object. This returns the length of the array.

animals.length
Array.push

MyArray.push(value);

Adds the specified value to the end of the array.

 animals = new Array("lion", "bear"); animals.push("tiger"); trace(animals); 

The Output window will display:

lions,bears, tigers

break

break;

Tells the ActionScript to skip the rest of the loop it is in.

 x = 0; while (true) {   if (x >= 100) {     break;   }   ++x; } 
delete

delete (reference);

Deletes the object or variable specified in reference. Useful for removing no-longer-needed variables in your ActionScript.

 x = 10; delete x; lion.teeth = "large"; delete lion.teeth; 
else

else{statement(s)}

Specifies the actions, clauses, arguments, or other conditional to run if the initial if statement returns false.

 if (x == 2) {   startDrag("myClip"); else{   stopDrag(); } 
else if
 else if (expression) {   statements } 

Specifies the actions, clauses, arguments, or other conditional to run if the initial if statement returns false and expression returns true .

 if (x == 1) {   gotoAndStop("africa"); } else if (x == 3) {   gotoAndStop("asia"); } 
eval

eval(expression)

Accesses variables, properties, objects, or movie clip by name.

this._x = eval(this._droptarget)._x;
for
 for (int; condition; next) {   statement; } 

int: The expression to evaluate before beginning the loop sequence.

condition: An expression that evaluates to true or false . The loop will execute the commands contained in it until the condition evaluates to false .

next: An expression to evaluate after each loop, usually an assignment using ++ or -- .

statement: The code that will execute when the condition is evaluated to true .

The loop evaluates the int value once, then begins a looping sequence until the condition evaluates to false .

 for (var x = 0; x < 5; ++x) {   trace ("ZooMX"); } 

The output window would show:

 ZooMX ZooMX ZooMX ZooMX ZooMX 
function
 function functionName (argument1, argument2){   statement(s) } 

A set of defined statements that perform a certain task. You can define a function in one location and call it from a different movie. The arguments are optional.

 function calcTax(price,tax){   cost = price*tax + price   return cost; } 
getTimer

getTimer();

Returns the number of milliseconds that have elapsed since the movie started playing.

time = getTimer();

returns a numeric value.

getURL

getUrl(url [,window[,variables]]);

Loads a document from a specific URL into a window, or passes variables to another application at a defined URL.

getURL("http://www.flashtfs.com", "_blank")
globalStyleFormat

globalStyleFormat.styleProperty

Object that lets you specify the style for all components in a movie. The styleProperty property can be one of the following:

 arrow, background, backgroundDisabled, check, darkshadow, face, foregroundDisabled, highlight, radioDot, scrollTrack, selection, selectionDisabled, selectionUnfocused, shadow, textAlign, textBold, textColor, textDisabled, textFont, textIndent, textItalic, textLeftMargin, textRightMargin, textSelected, textSize, textUnderline. 

The applyChanges method applies the changes you define for the globalStyleFormat object.

 globalStyleFormat.selection = 0xFF9933; globalStyleFormat.applyChanges(); 
gotoAndPlay

gotoAndPlay (frame);

Sends the playhead to the specified frame and plays from that frame.

gotoAndPlay(1);
gotoAndStop

gotoAndStop(frame);

Sends the playhead to the specified frame and stops at that frame.

gotoAndStop(1);
if
 if (condition){   statement; } 

Evaluates the condition given. If the condition is true , Flash runs the statements that follow.

 if (done != true) {   this.startDrag(); } 
loadMovie

loadMovie (url [location/target, variables]]);

Plays additional movies without closing the Flash Player. Use target to specify a particular movie-clip timeline.

loadMovie("movie.swf", _root.targetMC);
loadVariables

loadVariables (url [.location/target, variables]]);

Reads data from an external file and sets values for variables in a movie or movie clip. Also see LoadVars .

loadVariables("myvariables.txt", _root.variableTargetMC);
LoadVars.getBytesLoaded

varsObject.getBytesLoaded()

Returns the number of bytes loaded by the load or sendAndLoad method.

done = myVars.getBytesLoaded();
LoadVars.getBytesTotal

varsObject.getByteTotal()

Returns the total bytes for a load or sendAndLoad method.

total = myVars.getBytesTotal();
LoadVars.load

varsObject.load(url);

Loads the variables from the specified URL into the varsObject object.

 myVars = new LoadVars(); myVars.load("data.cfm"); 
LoadVars.send

varsObject.load(url, [target, method]);

Sends the variables to the specified URL. The target parameter specifies the frame in which any result is displayed.

 myVars = new LoadVars(); myVars.var1 = "update"; myVars.send("data.cfm", _blank); 
LoadVars.sendAndLoad

varsObject.load(url, targetObj, [method]);

Loads the variables from the specified URL into the targetObj object.

 myVars = new LoadVars(); myVars.var1 = "update"; myVars.sendAndLoad("data.cfm", myVars); 
Math.abs

Math.abs(x);

Computes the absolute value of the number specified by x .

Math.abs(-15);
Math.random

Math.random();

Creates a random number between 0.0 and 1.0.

trace (Math.random());

Outputs a random number.

MovieClip.attachMovie

anyMovieClip.attachMovie(idname, newname, depth);

idname: The name of the movie in the library to attach.

newname: A unique instance name that is going to be attached.

depth: An integer specifying the depth level where the movie is being placed.

Creates a new instance of a movie and attaches it to the movie specified by anyMovieClip .

this.attachMovie("lion", "lion"+x, x);
MovieClip.getBytesLoaded

anyMovieClip.getBytesLoaded()

Returns the number of bytes loaded for a movie-clip instance.

done = myClip.getBytesLoaded();
MovieClip.getBytesTotal

anyMovieClip.getByteTotal()

Returns the total bytes for a movie-clip instance.

total = myClip.getBytesTotal();
MovieClip.gotoAndPlay

anyMovieClip.gotoAndPlay(frame);

frame: The frame number or label where the playhead will be sent.

Starts playing the movie at the specified frame.

 zoo.gotoAndPlay(413); _level2.gotoAndPlay("rf"); 
MovieClip.gotoAndStop

anyMovieClip.gotoAndStop(frame);

frame: The frame number or label where the playhead will be sent.

Goes to the frame specified and stop.

 lion.gotoAndStop(73); lion.gotoAndStop("growl"); 
MovieClip.loadMovie

anyMovieClip.loadMovie(URL, variables);

URL: The absolute or relative URL for the SWF file to load.

variables: Specifies the method for sending variables. GET appends the variables to the end of the URL, POST send the variables in a separate HTTP header.

this.loadMovie(" games .swf");
MovieClip.on

The MovieClip object has the following event handlers:

 onData, onDragOut, onDragOver, onEnterFrame, onKeyDown, onKeyUp, onKillFocus, onLoad, onMouseDown, onMouseMove, onMouseUp, onPress, onRelease, onReleaseOutside, onRollOut, onRollOver, onSetFocus, onUnload 

Each event handler is invoked when the event occurs. You can specify a function that will occur when the event handler is invoked:

 anyMovieClip.onLoad = function() {   function; }; 
 anyMovieClip.onLoad = function() {   this._x = 10; }; 
MovieClip.play

anyMovieClip.play();

Plays the movie clip.

lion1.play();
MovieClip.removeMovieClip

anyMovieClip.removeMovieClip();

Removes the movie-clip instance created with the duplicateMovie action.

lion1.removeMoveClip();
MovieClip.startDrag

anyMovieClip.startDrag(lock, left, right, top, bottom);

lock: Specifies whether the draggable movie clip is locked to the center of the mouse position.

left, top, right, bottom: Values relative to the coordinates of the movie clip that constrains the drag of the clip.

this.startDrag();
MovieClip.stop

anyMovieClip.stop();

Stops the movie clip that is referred to.

lion1.stop();
MovieClip.stopDrag

anyMovieClip.stopDrag();

Ends a drag action started with the startDrag method.

this.stopDrag();
MovieClip.swapDepths
 anyMovieClip.swapDepths(depth): anyMovieClip.swapDepths(target); 

target: The movie-clip instance that is being swapped.

depth: The depth level that the movie clip is being swapped to.

Swaps the depth of two movie clips.

 lion1.swapDepths(lion2); lion1.swapDepths(100); 
MovieClip.unloadMovie

anyMovieClip.unloadMovie();

Removes the movie clip that was loaded with the loadMovie or attachMovie method.

lion2.unloadMovie();
new

new constructor(arguments);

Creates a new object, calls the function identified by the constructor argument, and passes additional optional arguments in the parentheses.

 tiger = new Cat ("large", "aggressive"); kitten = new Cat ("tiny", "playful"); 
null

null

A special keyword that can be assigned to variables. It will be returned by a function if no data was provided.

 if (common == null) {   gotoAndStop(10); } 
on
 on (mouseEvent) {   statement; } 

The mouseEvent argument can be press, release , releaseOutside , rollOver , rollOut , dragOver , dragOut , KeyPress("key") .

Specifies a mouse action or key press that triggers an action.

 on (rollOver, dragOver) {   gotoAndStop(5); } on (rollOut, dragOut) {   gotoAndStop(10); } 
onClipEvent
 onClipEvent(movieEvent) {   statements; } 

movieEvent: An event that executes actions that are assigned in the statements of the onClipEvent . Can have one of the following events ” load , unload , enterFrame , mouseMove , mouseDown , mouseUp , keyDown , keyUp , data .

Triggers actions defined in the statements for a specific instance of a movie clip.

 onClipEvent(load) {   gotoAndPlay(14); } 
play

play();

Move the playhead forward on the timeline.

 if (x == 2) {   play(); } else {   gotoAndPlay (45); } 
stop

stop();

Stops the current timeline from playing.

 if (x > 0 ) {   stop(); }else {   gotoAndStop(50); } 
this

this

A keyword that is used to refer to the current movie clip, the clip that contains the script.

 //sets the x position of the //current movie clip to 300 this._x = 300; 
trace

trace (expression);

Evaluates the expression and displays the result in the Output window. Similar to the alert function in JavaScript.

 trace (x+=5); trace ("Hi everyone!"); 
undefined

undefined

A keyword indicating that a variable has not yet been assigned a value.

 if (common == undefined) {   gotoAndStop(10); } 
updateAfterEvent

updateAfterEvent();

Updates the display after a movie-clip event has completed.

updateAfterEvent();
while
 while (condition) {   statements; } 

Runs a series of statements in the loop as long as the loop conditions continues to be true .

 while (x > 5) {   trace(hammerhead);   x++; } 
I l @ ve RuBoard


Macromedia Flash MX. Training from the Source
Macromedia Flash MX: Training from the Source
ISBN: 0201794829
EAN: 2147483647
Year: 2002
Pages: 115
Authors: Chrissy Rey

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net