About language punctuators
129
9.
Select File > Save to save the Flash document.
10.
Select Control > Test Movie to test the code in the authoring environment.
In the SWF file, an error message is displayed if you click the Button instance on the Stage
when you do not have text in the
firstName_ti
TextInput component. This error
appears in the Label component and informs users that they need to enter a first name.
The next example using curly braces shows how to create and define properties within an
object. In this example, properties are defined in the object by specifying the variable names
within the curly brace (
{}
) punctuators:
var myObject:Object = {id:"cst94121", firstName:"John", middleName:"H.",
lastName:"Doe"};
var i:String;
for (i in myObject) {
trace(i + ": " + myObject[i]);
}
/*
id: cst94121
firstName: John
middleName: H.
lastName: Doe
*/
You can also use empty curly braces as a syntax shortcut for the
new Object()
function. For
example, the following code creates an empty Object instance:
var myObject:Object = {};
Parentheses
When you define a function in ActionScript, you place parameters inside parentheses [
()
]
punctuators, as shown in the following lines of code:
function myFunction(myName:String, myAge:Number, happy:Boolean):Void {
// Your code goes here.
}
When you call a function, you also include any of the parameters you pass to the function in
parentheses, as shown in the following example:
myFunction("Carl", 78, true);
You can use parentheses to override the ActionScript order of precedence or to make your
ActionScript statements easier to read. This means you can change the order in which values
are computed by placing brackets around certain values, as seen in the following example:
var computedValue:Number = (circleClip._x + 20) * 0.8;
TI
P
Remember to make sure each opening curly brace has a matching closing brace.
Summary of Contents for FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Page 1: ...Learning ActionScript 2 0 in Flash...
Page 8: ...8 Contents...
Page 18: ...18 Introduction...
Page 30: ...30 What s New in Flash 8 ActionScript...
Page 66: ...66 Writing and Editing ActionScript 2 0...
Page 328: ...328 Interfaces...
Page 350: ...350 Handling Events...
Page 590: ...590 Creating Interaction with ActionScript...
Page 710: ...710 Understanding Security...
Page 730: ...730 Debugging Applications...
Page 780: ...780 Deprecated Flash 4 operators...
Page 830: ...830 Index...