«
»

Actionscript 3.0, Flex 3, Object Oriented Design

Getting the Class of an object in AS3

11.04.08 | 24 Comments

A quick and useful titbit: in order to get the class of an object use the following code:

   1: static function getClass(obj:Object):Class {
   2:     return Class(getDefinitionByName(getQualifiedClassName(obj)));
   3: }

This is great for checking the type of an object.  For example, if you have an object myObj1 and you want to confirm that it is of the same type as myObj2 you can write:

   1: if (myObj1 is getClass(myObj2)) {
   2:     trace("These objects are of the same class!");
   3: }

24 Comments

have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

:

:


«
»