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
change
to 30 (in line 3 of the code), the value of
myNum
doesn't look to
otherNum
that it receives (in line 2 of the code).
myNum
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
to
and copy the value into
myNum
15
for its value. The
myNum
otherNum
remains
otherNum
variable contains the value of
otherNum
. When you
because
15
About variables
93
Need help?
Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?
Questions and answers