as 
operator  
Usage

expression as datatype
Language version: ActionScript 3.0
Player version: Flash Player 9

Evaluates whether an expression specified by the first operand is a member of the data type specified by the second operand. If the first operand is a member of the data type, the result is the first operand. Otherwise, the result is the value null.

The expression used for the second operand must evaluate to a data type.

Operands

expression:* — The value to check against the data type specified.

datatype:Class — The data type used to evaluate the expression operand. The special * type, which means untyped, cannot be used.
Result

Object — The result is expression if expression is a member of the data type specified in datatype. Otherwise, the result is the value null.

Example
How to use examples
The following example creates a simple array named myArray and uses the as operator with various data types.
public var myArray:Array = ["one", "two", "three"];
trace(myArray as Array); // one,two,three
trace(myArray as Number); // null
trace(myArray as int); // null

===================================================================================================
is  
operator  
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 DisplayObject classes, and whether it implements the IEventDispatcher 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

===================================================================================================
instanceof  
operator  
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 DisplayObject classes. The result is true with the Sprite class and the DisplayObject class because the prototype objects for Sprite and DisplayObject 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 DisplayObject 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

'기타 > Old' 카테고리의 다른 글

for in 구문  (0) 2008.04.16
실행시간 시간차이 구하기  (0) 2008.04.16
타입 캐스팅  (0) 2008.04.16
변수 관련 기초 공부  (1) 2008.04.16
OOP ?일까나....  (0) 2008.04.16

+ Recent posts