User Guide
334 Chapter 2: ActionScript Language Reference
instanceof
Availability
Flash Player 6.
Usage
object
instanceof class
Parameters
object
An ActionScript object.
class A reference to an ActionScript constructor function, such as String or Date.
Returns
If object is an instance of class, instanceof returns true; false otherwise. Also, _global
instanceof Object
returns false.
Description
Operator; determines whether an object belongs to a specified class. Tests whether object is an
instance of
class.
The
instanceof operator does not convert primitive types to wrapper objects. For example, the
following code returns
true:
new String("Hello") instanceof String;
The following code returns false:
"Hello" instanceof String;
Example
In the following example, a for loop is used to loop through the SWF file and trace only
TextInput component instances. The instance names appear in the output.
for (var i in this) {
if (this[i] instanceof mx.controls.TextInput) {
trace("Instance \""+i+"\" is a TextInput component instance.");
}
}
See also
typeof
CHAPTER 2
ActionScript Language Reference