我有一门包含许多嵌入式资产的课程。
在类中,我想按名称获取资产的类定义。我尝试过使用 getDefinitionByName() 和 ApplicationDomain.currentDomain.getDefinition() 但都不起作用。
例子:
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");