Usage
|
expression1 is
expression2 |
| Language version: |
ActionScript 3.0 |
| Player version: |
Flash Player 9 |
Evaluates whether an object is compatible
with a specific data type, class, or interface. Use the is operator instead of the
instanceof operator for type comparisons. You can also use the is operator to check whether an
object implements an interface.
Result
|
Boolean — A value of
true if expression1 is
compatible with the data type, class, or interface specified in
expression2, and false otherwise. |
Example How to use examples The following
example creates an instance of the Sprite class named
mySprite and
uses the
is operator
to test whether
mySprite is an
instance of the Sprite and D
isplayObject
classes, and whether it implements the IEventD
ispatcher interface.
import flash.display.*;
import flash.events.IEventDispatcher;
var mySprite:Sprite = new Sprite();
trace(mySprite is Sprite); // true
trace(mySprite is DisplayObject); // true
trace(mySprite is IEventDispatcher); // true
Usage
|
expression instanceof function |
| Language version: |
ActionScript 3.0 |
| Player version: |
Flash Player 9 |
Evaluates whether an expression's prototype chain includes the prototype
object for function. The instanceof operator is included for backward compatibility with ECMAScript
edition 3, and may be useful for advanced programmers who choose to use
prototype-based inheritance with constructor functions instead of classes.
To check whether an object is a member of a
specific data type, use the is operator.
When used with classes, the instanceof operator is similar to the is operator because a class's
prototype chain includes all of its superclasses. Interfaces, however, are not
included on prototype chains, so the instanceof operator always
results in false when used with interfaces, whereas the is operator results in
true if an object belongs to a class that implements the specified
interface.
Note: The ActionScript is operator is the equivalent of the Java instanceof
operator.
Operands
|
expression:Object — The object that contains the prototype
chain to evaluate. |
|
function:Object — A function object (or class).
|
Result
|
Boolean — Returns true
if the prototype chain of expression includes the prototype object
for function, and false otherwise. |
Example How to use examples The following
example creates an instance of the Sprite class named
mySprite and
uses the
instanceof operator to test whether the prototype chain of
mySprite includes the prototype objects of the Sprite and D
isplayObject classes. The result
is true with the Sprite class and the
D
isplayObject class because the prototype
objects for Sprite and D
isplayObject are on the
prototype chain of
mySprite.
var mySprite:Sprite = new Sprite();
trace(mySprite instanceof Sprite); // true
trace(mySprite instanceof DisplayObject); // true
The following example uses the IBitmapDrawable interface to show
that the
instanceof operator does not work with interfaces. The
is operator results in
true because the D
isplayObject
class, which
is a superclass of the Sprite
class, implements the IBitmapDrawable interface.
var mySprite:Sprite = new Sprite();
trace(mySprite instanceof IBitmapDrawable); // false
trace(mySprite is IBitmapDrawable); // true