Insert many charts using an array

In AS3, you can embed graphics in a class variable:

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

I have hundreds of assets in this project that I am doing, so I want to embed the assets in an array for quick access.

Can I do something like this? This is not a compilation, so I wonder if this is 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")],
        ]
+5
source share
3 answers

You can also embed assets in one FLA. In the FLA library, give each of them a class name, for example, "graphics.menu.RightSquare", then export it as a SWC. Set up your Flash Builder project to load SWC as an external library. Then you can do something like:

import graphics.menu.*;

new RightSquare();
+4

, . :

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;
    }
}
+5

, Flex .

You must use [Embed] the metadata tag before defining the variable, where the variable is of type Class.

However, you can:

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

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

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

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

public var menuAssets:Array = [TopMenuItem, LeftMenuItem, 
                               RightMenuItem, BottomMenuItem];
+4
source

All Articles