Skip to main content
Inspiring
December 15, 2007
Question

typeof in AS3

so i used to do sh_t like

switch ( typeof( obj) ){
case "movieclip": etc.
case "string" etc.
}

alot. now i have this 'is' thing im left with really irritating - and probably processor heeavy - multiple ifs like this:

if ( obj is thisObject ){
do this...
} else if ( obj is thatObject ){
do that...
} else if ( obj is otherObject ){
do other
}

usch! very nasty. is there any way i can get back to using my tidy switches instead?
Ce sujet a été fermé aux réponses.

3 commentaires

Participant
April 21, 2013

try

switch ( true ) {

    case object is MovieClip:

    case object is Sprite:

}

it's probably also more readable that typeof as well.

Participant
August 6, 2011

typeof is still around, a little different though: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/operators.html?filter_flash=cs5&filter_flashplayer=10.2&filter_air=2.6#typeof

Inspiring
August 6, 2011

with very few execptions, everything would be the sme

"object" -

probably enough to tell a string apart from a moiecli

p,  but not to distinguish a square from a ball


Inspiring
December 17, 2007
It's probably overkill but have a look at these:

describeType()
getQualifiedSuperclassName()
getQualifiedClassName()

these return the class types in a string (as well as other stuff), in various forms. Might be worth it for longer switches.