Assigning Data Types To Elements - MACROMEDIA FLASH MX 2004 - ACTIONSCRIPT Reference Manual

Actionscript reference guide
Hide thumbs Also See for FLASH MX 2004 - ACTIONSCRIPT:
Table of Contents

Advertisement

Determining an item's data type
While testing and debugging your programs, you may discover problems that seem to be related
to the data types of different items. In these cases, you may want to determine an item's data type.
To do so, use the
trace(typeof(variableName));
For more information on testing and debugging, see
Scripts," on page

Assigning data types to elements

Flash automatically assigns data types to the following kinds of language elements, as discussed in
the next section,
Variables
Parameters passed to a function, method, or class
Values returned from a function or method
Objects created as subclasses of existing classes
However, you can also explicitly assign data types to items, which can help prevent or diagnose
certain errors in your scripts. For more information, see
Automatic data typing
In Flash, you do not need to explicitly define an item as holding either a number, a string, or
other data type. Flash determines the data type of an item when it is assigned:
var x = 3;
In the expression
determines that it is of the number data type. A later assignment may change the type of
example, the statement
assigned a value has a type of
ActionScript converts data types automatically when an expression requires it. For example, when
you pass a value to the
sends it to the Output panel. In expressions with operators, ActionScript converts data types as
needed; for example, when used with a string, the
a string.
"Next in line, number " + 7
ActionScript converts the number 7 to the string
resulting in the following string:
"Next in line, number 7"
operator, as shown in this example:
typeof
55.
"Automatic data
typing":
, Flash evaluates the element on the right side of the operator and
var x = 3
changes the type of
x = "hello"
undefined
action,
trace()
Chapter 3, "Writing and Debugging
"Strict data typing" on page
to a string. A variable that hasn't been
x
.
automatically converts the value to a string and
trace()
operator expects the other operand to be
+
and adds it to the end of the first string,
"7"
Assigning data types to elements
38.
; for
x
37

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH MX 2004 - ACTIONSCRIPT and is the answer not in the manual?

Subscribe to Our Youtube Channel

Table of Contents