Posted By

adrianparr on 04/19/10


Tagged

class name as3 Reference getDefinitionByName ClassReference


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

jhoard
socialflasher
thastyle
tspitzr


AS3 Get a Class Reference by Class Name


 / Published in: ActionScript 3
 

URL: http://www.mikechambers.com/blog/2006/06/22/actionscript-3-get-a-class-reference-by-class-name/

  1. package
  2. {
  3. import flash.display.Sprite;
  4. import flash.utils.getDefinitionByName;
  5.  
  6. public class DynamicCall extends Sprite
  7. {
  8. public function DynamicCall()
  9. {
  10. var ClassReference:Class = getDefinitionByName("String") as Class;
  11. var s:String = (new ClassReference("foo=") as String);
  12. trace(s);
  13. }
  14. }
  15. }
  16.  
  17. // This basically creates an instance of the String class, from the
  18. // class name 'String'. getDefinitionByName takes the entire class
  19. // path, so if you wanted to create an instance of MovieClip, you would
  20. // provide the entire path:
  21. // var ClassReference:Class = getDefinitionByName("flash.display.MovieClip") as Class;

Report this snippet  

You need to login to post a comment.