03.05.2013 Views

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Variables can hold any data type (for example, String, Number, Boolean, Object, or<br />

MovieClip). The Timeline of each SWF file <strong>and</strong> movie clip has its own set of variables, <strong>and</strong><br />

each variable has its own value independent of variables on other Timelines.<br />

Strict data typing is not supported inside a set statement. If you use this statement to set a<br />

variable to a value whose data type is different from the data type associated with the variable<br />

in a class file, no compiler error is generated.<br />

A subtle but important distinction to bear in mind is that the parameter variableString is a<br />

string, not a variable name. If you pass an existing variable name as the first parameter to<br />

set() without enclosing the name in quotation marks (""), the variable is evaluated before<br />

the value of expression is assigned to it. For example, if you create a string variable named<br />

myVariable <strong>and</strong> assign it the value "Tuesday," <strong>and</strong> then forget to use quotation marks, you<br />

will inadvertently create a new variable named Tuesday that contains the value you intended<br />

to assign to myVariable:<br />

var myVariable:String = "Tuesday";<br />

set (myVariable, "Saturday");<br />

trace(myVariable); // outputs Tuesday<br />

trace(Tuesday); // outputs Saturday<br />

You can avoid this situation by using quotation marks (""):<br />

set ("myVariable", "Saturday");<br />

trace(myVariable); //outputs Saturday<br />

Parameters<br />

variableString:String - A string that names a variable to hold the value of the<br />

expression parameter.<br />

Example<br />

In the following example, you assign a value to a variable. You are assigning the value of<br />

"Jakob" to the name variable.<br />

set("name", "Jakob");<br />

trace(name);<br />

The following code loops three times <strong>and</strong> creates three new variables, called caption0,<br />

caption1, <strong>and</strong> caption2:<br />

for (var i = 0; i < 3; i++) {<br />

set("caption" + i, "this is caption " + i);<br />

}<br />

trace(caption0);<br />

trace(caption1);<br />

trace(caption2);<br />

Statements 197

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!