开发者

Reducing the number of Class objects to access embedded resources

开发者 https://www.devze.com 2023-01-25 05:03 出处:网络
开发者_如何学编程I\'m building a Flex project with a lot of embedded bitmaps and such. The usual method for getting to the bitmaps in Actionscript seems to be to do something like

开发者_如何学编程I'm building a Flex project with a lot of embedded bitmaps and such. The usual method for getting to the bitmaps in Actionscript seems to be to do something like

   [Bindable] [Embed(source = '../lib/WhiteFencePost.png')]
    private static var clsObstacleFencePost : Class;
   var bitmap : BitmapAsset = new clsObstacleFencePost();

I've already got several dozen of these things, and I can easily see ending up with hundreds of them by the time the project's done. Is there some way that I can avoid creating a Class for every bitmap?


Try to create an assets manager with static classes like this.

class AssetManager
{

    [Bindable]
    [Embed(source = '../lib/WhiteFencePost.png')]
    public static var WhiteFencePost:Class;

    [Bindable]
    [Embed(source = '../lib/BlackFencePost.png')]
    public static var BlackFencePost:Class;

}

Then you can use the images like this

myImage1.source = AssetManager.WhiteFencePost;
myImage2.source = AssetManager.WhiteFencePost;
myImage3.source = AssetManager.WhiteFencePost;    
myImage4.source = AssetManager.BlackFencePost;

You do not need to define a new instance of the Class images that you want to use.


There are ways... Pack all files into zip - embed zip - unpack with any zip library for actionscript, then Loader.loadBytes pic needed. Zip contents can be enumerated, so if you know what to do with files by name, you don't even need file list in application.

0

精彩评论

暂无评论...
验证码 换一张
取 消