View comments | RSS feed

typeof operator

typeof(expression)

Evaluates the expression and returns a string specifying whether the expression is a String, MovieClip, Object, Function, Number, or Boolean value.

Availability: ActionScript 1.0; Flash Player 5

Operands

expression : Object - A string, movie clip, button, object, or function.

Returns

String - A String representation of the type of expression. The following table shows the results of the typeof operator on each type of expression.

Expression Type

Result

String

string

Movie clip

movieclip

Button

object

Text field

object

Number

number

Boolean

boolean

Object

object

Function

function

See also

instanceof operator


Version 8

Comments


Fumio Nonaka said on Oct 16, 2005 at 1:19 PM :
[Returns]
Addition:
Undefined undefined
Null null
Francis Cheng said on Nov 3, 2005 at 3:21 PM :
Thanks Fumio. Something else to keep in mind is that if you wrap a primitive value (Boolean, Number or String) in an object with the "new" operator, the return value of the typeof operator will be "object". The entries for Boolean, Number, and String in the table above apply to Boolean, Number, and String literals.

trace (typeof "hello"); // output: string

var greetingLiteral:String = "hello";
trace (typeof greetingLiteral); // output: string

var greeting:String = new String("hello");
trace (typeof greeting); // output: object
thx1138 said on Feb 28, 2006 at 5:17 PM :
A way I use to test for arrays is:

var isArray = (myVar.length != undefined) ? true : false;
thx1138 said on Mar 29, 2006 at 7:11 PM :
Sometimes when you need more information when dealing with components you can check the className property like so:

// add a TextInput to the stage with an instance name of myTextInput
trace(myTextInput.className); // outputs TextInput
No screen name said on Sep 19, 2006 at 11:48 AM :
typeof(expression) gives back 2 kind of MovieClip types
if the MovieClip was created on the stage compilation time, it gives back "mc" as type identifier
when it's been created runtime (createEmptyMovieClip) it gives back "movieclip" according to the documentation

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00001857.html