ASSIGNING A VALUE TO A VARIABLE IN FLASH



You can assign a string to a variable. A string is any sequence of characters consisting of any combination of letters, numbers, or punctuation marks. You can use a string variable to store string values such as text or a URL. You cannot perform mathematical operations on a string even if the string is a number. When assigning a string to a variable, you must include the string in single or double quotation marks. This example, userName = "John Smith";, stores a string to the variable userName.

You can assign a number to a variable and use the number as a counter, in a mathematical calculation, or to set a property. A number assigned to a variable can be the result of a mathematical calculation. These examples all assign numbers to a variable: a = 5;, x = a + 25;, and x = 5 + 7; . Any expression that returns a number that is assigned to a variable, assigns a number to the variable. ActionScript stores numbers as floating-point numbers. A floating-point number is a number with no fixed number of digits before or after the decimal point.

You can use a Boolean when you want to set a condition to true or false, evaluate whether a condition is true or false, or compare values. Booleans are often used with logical operators. When assigning a Boolean, the value is always either the word true or the word false or an expression that evaluates to true or false. This example, x = false;, assigns a Boolean to a variable.

See the below steps to perform assigning a value to a variable:

1) Select the frame, button, or movie clip to which you want to add ActionScript.

2) Click Window from menu bar and then Actions to open the Actions panel.

3) Assign values to variables.

4) Use the variables in an expression.

5) If you associate the variables with dynamic text boxes, you can display the values the variables return to the user.

6) Move to the test environment.

7) Click the button to test your movie.

8) The script assigned the values needed to execute the script to variables. Your movie will perform the actions the same way it would have if you had used literal values.



Several characters cannot be included in a string unless they are preceded with a backslash. The table shown here lists these characters.

ESCAPE SEQUENCE and CHARACTER

\: Double quotation mark
\: Single quotation mark
\\: Backslash
\b: Backspace character (ASCII 8)
\f: Form feed character (ASCII 12)
\n: Line feed character (ASCII 10)
\r: Carriage return character (ASCII 13)
\t: Tab character (ASCII 9)
\000 - \377: A byte specified in octal
\x00 - \xFF: A byte specified in hexadecimal
\u0000 - \uFFFF: A 16-bit Unicode character specified in hexadecimal.