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.

var name:String = "Cola";<br />

var instrument:String = "Drums";<br />

trace(name + " plays " + instrument); // output: Cola plays Drums<br />

Note: Flash Lite 1.x does not support the addition (+) operator for concatenating strings. For<br />

Flash Lite 1.x, you must use the add operator to concatenate strings.<br />

Usage 2: This statement adds the integers 2 <strong>and</strong> 3 <strong>and</strong> displays the resulting integer, 5, in the<br />

Output panel:<br />

trace(2 + 3); // output: 5<br />

This statement adds the floating-point numbers 2.5 <strong>and</strong> 3.25 <strong>and</strong> displays the resulting<br />

floating-point number, 5.75, in the Output panel<br />

trace(2.5 + 3.25); // output: 5.75<br />

Usage 3: Variables associated with dynamic <strong>and</strong> input text fields have the data type String. In<br />

the following example, the variable deposit is an input text field on the Stage. After a user<br />

enters a deposit amount, the script attempts to add deposit to oldBalance. However,<br />

because deposit is a String data type, the script concatenates (combines to form one string)<br />

the variable values rather than summing them.<br />

var oldBalance:Number = 1345.23;<br />

var currentBalance = deposit_txt.text + oldBalance;<br />

trace(currentBalance);<br />

For example, if a user enters 475 in the deposit text field, the trace() function sends the<br />

value 4751345.23 to the Output panel. To correct this, use the Number() function to convert<br />

the string to a number, as in the following:<br />

var oldBalance:Number = 1345.23;<br />

var currentBalance:Number = Number(deposit_txt.text) + oldBalance;<br />

trace(currentBalance);<br />

The following example shows how numeric sums to the right of a string expression are not<br />

calculated:<br />

var a:String = 3 + 10 + "asdf";<br />

trace(a); // 13asdf<br />

var b:String = "asdf" + 3 + 10;<br />

trace(b); // asdf310<br />

+= addition assignment operator<br />

expression1 += expression2<br />

Assigns expression1 the value of expression1+ expression2. For example, the following<br />

two statements have the same result:<br />

x += y;<br />

x = x + y;<br />

Operators 111

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

Saved successfully!

Ooh no, something went wrong!