Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embed many graphics using an array

In AS3 you can embed a graphic into a Class variable:

     [Embed(source="MenuAssets.swf", symbol="topSquare")]
        public var TopMenuItem:Class;

I have hundreds of assets in this one website project I'm doing, so I want to embed assets into an array for quick access.

Can I do something like this? Its not compiling so I'm wondering whether its possible.

        public var MenuAssets:Array = [
           [Embed(source="MenuAssets.swf", symbol="topSquare")],
           [Embed(source="MenuAssets.swf", symbol="botSquare")],
           [Embed(source="MenuAssets.swf", symbol="leftSquare")],
           [Embed(source="MenuAssets.swf", symbol="rightSquare")],
        ]
like image 742
Robin Rodricks Avatar asked Jul 16 '10 10:07

Robin Rodricks


2 Answers

I'm afraid you can't. What you could do is the following:

public class Assets {
    [Embed(source="MenuAssets.swf", symbol="topSquare")]
    public static const TOP_SQUARE:Class;
    //... more assets ...
    public static function getAssets():Array {
        var ret:Array = [];
        for each (var s:String in describeType(Assets).constant.@name) ret.push(Assets[s]);
        return ret;
    }
}
like image 67
back2dos Avatar answered Oct 01 '22 15:10

back2dos


You could also embed the assets in a single FLA. In the FLA's library, give each one a class name like "graphics.menu.RightSquare" then export it as a SWC. Configure your Flash Builder project to load the SWC as an external library. Then you can do something like:

import graphics.menu.*;

new RightSquare();
like image 41
Casey Avatar answered Oct 01 '22 15:10

Casey