About variables
93
3.
Type the following code on Frame 1 of the Timeline.
// Does not work
function badClickListener(evt:Object):Void {
getURL(targetUrl);
var targetUrl:String = "http://www.macromedia.com";
}
bad_button.addEventListener("click", badClickListener);
4.
Select Control > Test Movie, and notice that the button does not work (it doesn’t open the
web page).
5.
Drag another Button component onto the Stage. Select the button.
6.
Open the Property inspector, and type
good_button
into the Instance Name text box.
7.
Add the following ActionScript to Frame 1 of the Timeline (following the previous
ActionScript you added):
// Works
function goodClickListener(evt:Object):Void {
var targetUrl:String = "http://www.macromedia.com";
getURL(targetUrl);
}
good_button.addEventListener("click", goodClickListener);
8.
Select Control > Test Movie and click the second button you added to the Stage.
This button properly opens the web page.
The type of data that a variable contains affects how and when the variable’s value changes.
Primitive data types, such as strings and numbers, are
passed by value
, which means the current
value of the variable is used rather than a reference to that value. Examples of complex data
types include the Array and Object data types.
In the following example, you set
myNum
to
15
and copy the value into
otherNum
. When you
change
myNum
to 30 (in line 3 of the code), the value of
otherNum
remains
15
because
otherNum
doesn’t look to
myNum
for its value. The
otherNum
variable contains the value of
myNum
that it receives (in line 2 of the code).
To use variables in your ActionScript:
1.
Create a new Flash document, and save it as
var_example.fla
.
2.
Select Frame 1 of the Timeline, and type the following code into the Actions panel:
var myNum:Number = 15;
var otherNum:Number = myNum;
myNum = 30;
trace(myNum); // 30
trace(otherNum); // 15
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...