Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Flex/AS3, how do I get a class definition of an embedded asset with getDefinitionByName

I have a class with many embedded assets.

Within the class, I would like to get the class definition of an asset by name. I have tried using getDefinitionByName(), and also ApplicationDomain.currentDomain.getDefinition() but neither work.

Example:

public class MyClass
{
  [Embed(source="images/image1.png")] private static var Image1Class:Class;
  [Embed(source="images/image2.png")] private static var Image2Class:Class;
  [Embed(source="images/image3.png")] private static var Image3Class:Class;

  private var _image:Bitmap;

  public function MyClass(name:String)
  {
    var ClassDef:Class = getDefinitionByName(name) as Class;  //<<-- Fails
    _image = new ClassDef() as Bitmap;    
  }
}

var cls:MyClass = new MyClass("Image1Class");
like image 789
user8399 Avatar asked Sep 17 '08 20:09

user8399


1 Answers

This doesn't answer your question, but it may solve your problem. I believe doing something like this should work:

public class MyClass
{
  [Embed(source="images/image1.png")] private static var Image1Class:Class;
  [Embed(source="images/image2.png")] private static var Image2Class:Class;
  [Embed(source="images/image3.png")] private static var Image3Class:Class;

  private var _image:Bitmap;

  public function MyClass(name:String)
  {
    _image = new this[name]() as Bitmap;    
  }
}

var cls:MyClass = new MyClass("Image1Class");

I'm having a tough time remembering if bracket notation works on sealed classes. If it doesn't, a simple solution is to mark the class as dynamic.

like image 94
Marc Hughes Avatar answered Sep 21 '22 07:09

Marc Hughes