views:

12719

answers:

5

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.

+2  A: 

Hello,

instead of

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

Use

myImage.source = Resource.SHIPS_1;

The embedding is correct. :D the way you use it is wrong :)

Adrian,


TiMeister Blog

Adrian Pirvulescu
But this way of embedding causes a lot of hassle. Isn't there a better way?
Tom
Edit: how can Resource.SHIPS_1 be right when Resource is not even defined?
Tom
1. Resource.SHIPS_1 must be defined previously.2. There is no other way.. except by embedding inside css files, but that is even worse :(
Adrian Pirvulescu
Really? Seems awkward to me.
Tom
you don't need to instantiate Resource, you defined SHIPS_1 as a static contstant so you just use it as the source like adrian pointed out.
Ronn
+2  A: 

This is really what Flash CS4 is for. Your way seems fine to me though - although I wouldn't use all caps for a class name even if it is a constant. Just put your head down and get copy-pasting!

Alternatively you could load the files at runtime.

Iain
+1 on loading the files at runtime. Otherwise, you could end up with a larger SWF than you really should need.
Jacob
You're saying I should load them from a webserver then?
Tom
The (big) disadvantage of that would be that everyone can just download all my graphical contents.
Tom
+3  A: 

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.

gmj
A: 

Am sorry this is actually a question...I need to even display the images using actionscript, 'cause i i want the image to load dynamically when an event is triggered. Can anyone please help me on this?

Babatunde
A: 

Is it possible for someone to example gmj's position?