
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Datatype Conversion
|
67
examine the cases in which automatic conversions will occur and the results of con-
verting a datum from one type to another.
Datatype Conversion
Take a closer look at the example from the previous section. In that example, each
datum—“1” and 2—belonged to its own datatype; the first was a string and the sec-
ond was a number. We saw that the interpreter joined the two values together to
form the string “12”. Note that the interpreter first had to convert the number 2 into
the string “2”. Only after that automatic conversion was performed could the value
“2” be joined (concatenated) to the string “1”.
Datatype conversion simply means changing the type of a datum. Not all datatype
conversions are automatic; we may also change a datum’s type explicitly in order to
override the default datatype conversion that ActionScript would otherwise perform.
Explicit conversion is known as typecasting, or simply casting.
Automatic Type Conversion
Whenever we use a value in a context that does not match the expected datatype, the
interpreter attempts a conversion. That is, if the interpreter expects data of type A,
and we provide data of type B, the interpreter will attempt to convert our type B data
into type A data. For example, in the following code we use the string “Flash” ...