joe zhou
joe zhou

Reputation: 9

how to get class using embed tag from a library project in flash?

I created a library project, which contains an embed image like below in class AssetLib.

   [Embed(source="Frame_Title_BG.png")]
   private var Frame_Title_BG:Class;

then I exported the swc to my existing actionscript project.So i assume that the img Frame_Title_BG should be in the memoroy,but when i try to created the class

var assetCLs:Class = getClassByAlias('Frame_Title_BG');
var asset = new  assetCLs();

I was not able to get the assetCLs;

In my mind, all the class should be in the applicationDomain.

So how can i use the Class in my current project?

Upvotes: 0

Views: 259

Answers (2)

Michael
Michael

Reputation: 3871

As an alternative you can define the asset as a public static variable, then you should be able to do the following:

public class AssetLib
{
    [Embed(source="Frame_Title_BG.png")]
    public static var Frame_Title_BG:Class;
}

Then in another class:

var frameBG:Bitmap = new AssetLib.Frame_Title_BG() as Bitmap;
addChild( frameBG );

or even

var frameBG:Bitmap = new AssetLib['Frame_Title_BG']() as Bitmap;
addChild( frameBG );

Just another option.

Upvotes: 1

fsbmain
fsbmain

Reputation: 5267

add "ClassHolder_" before the embed class name:

    var imageClass:Class= ApplicationDomain.currentDomain.getDefinition('AssetLib_Frame_Title_BG') as Class;
    var bitmap:DisplayObject = new imageClass();
    addChild(bitmap);

Upvotes: 0

Related Questions