Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Howto embed images in Actionscript 3 / Flex 3 the right way?

I'm creating a game where a lot of images are being used in Actionscript / Flex 3 (Flash). Now that I've reached the designer stage, I have to work out a structural way of using embedded images (which have to be manipulated with rotation, color, etc.).

Unfortunately, after investigating a bit, it looks like you have to manually embed images before you can use them. I currently have it setup like this:

Resource.as class file:

package
{
    public final class Resource
    {
        [Embed (source="/assets/ships/1.gif" )]
        public static const SHIPS_1:Class;
    }
}

So, just for one ship I so for have to:

Put the image in the correct folder with the correct name Name it in the same way in the Resource.as file Create the constant with the same name in the Resource.as file

Even though this should all be possible by simply putting the file in a specified folder.

To make things even worse, I still have to call it using:

var test:Bitmap = new Resource.SHIPS_1();

There must be better ways to handle resources when creating very huge applications? Imagine I need thousands of images, this system simply wouldn't fit.

like image 931
Tom Avatar asked Jun 27 '09 20:06

Tom


1 Answers

If you need to handle a large number of resources you can follow these 3 steps:

  1. Place them in an uncompressed zip archive

  2. Embed the zip file as binary data:

    [Embed(source = 'resources.zip', mimeType = 'application/octet-stream')]

  3. Access the resources using FZip

If you choose a different method that involves loading external files be aware that some flash game websites require the games they host to be contained within a single swf file.

like image 189
gmj Avatar answered Oct 21 '22 16:10

gmj