View comments | RSS feed

typeof

Availability

Flash Player 5.

Usage

typeof(expression) : String

Parameters

expression A string, movie clip, button, object, or function.

Description

Operator; a unary operator placed before a single parameter. The typeof operator causes the Flash interpreter to evaluate expression; the result is a string specifying whether the expression is a string, movie clip, object, function, number, or Boolean value. The following table shows the results of the typeof operator on each type of expression:

nu
Parameter Output

String

string

Movie clip

movieclip

Button

object

Text field

object

Number

number

Boolean

boolean

Object

object

Function

function

null

null

undefined

undefined

Example

In the following example, all instances in a SWF file and their types are traced and displayed in the Output panel.

for (i in _root) {
   trace("_root."+i+" ("+typeof (_root[i])+")");
}

Comments


harleybl said on Nov 2, 2004 at 11:39 AM :
It seems kind of stupid that typeof button returns "object" instead of button.
headwinds said on Dec 12, 2004 at 9:49 AM :
Perhaps, instead of "object" for the button, it could return "component" as
there are associated graphics...

that's a powerful example but i personally found it a bit beyond my use --
so I wrote this test which simplified things in my mind...

myStringObject = new String();
myObject = new Object();
myMovieClipObject = new MovieClip();
myNumber = 6,
myString = "hello World";
myMovieClip = clipOnStage_mc;
myFunction = findType;

myArray = [myString, myObject, myMovieClip, myNumber, myString,
myMovieClip, myFunction ];

function findType() {
for ( i in myArray) {
var myType: String = typeof (myArray[i]) ;
trace ("type = " + myType);
}
}

findType();
No screen name said on Jul 1, 2005 at 12:27 PM :
A reference to the "instanceof" operator here might address the comments above.

 

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

Current page: http://livedocs.adobe.com/flash/mx2004/main_7_2/00001865.html