
Typing 33
Type detection
To perform type detection, you should use is rather than typeof or instanceof. The is
function examines types, whereas the
instanceof function looks at the prototype chain. The
instanceof function has been deprecated.
For example:
class B {
public function B() {}
}
class A extends B {
public function A() {
super();
}
}
class Main extends MovieClip {
public function Main() {
var a:A = new A();
trace(a instanceof B); // false; instanceof is deprecated.
trace(a instanceof A); // false; instanceof is deprecated.
trace(a is B); // true
trace(a is A); // true
}
}
Primitive types
In ActionScript 3.0, there is no longer a distinction between primitive types such as strings
and instances of the String class. All strings are instances of String; every datatype is an
instance of some class. The same is true for numbers and Booleans. For example:
print("test" == String("test")); // true
print("test" === String("test")); // true
print(45 == new Number(45)); // true
print(45 === new Number(45)); // true
print("one;two;three".substring(4,7)); // "two"
print((255).toString(16)); // "ff"
Non-assignment expressions
A non-assignment expression is any expression where a value is not assigned to a property (or
a variable or argument); for example:
var myVar : hintString ? String : Number;
Commentaires sur ces manuels