AS3 Get a Class Reference by Class Name


/ Published in: ActionScript 3



Copy this code and paste it in your HTML
  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;

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.