views:

66

answers:

2

Hi, i would like to know what is the more practical way to embed many images using actionscript. Firstly, i don't want to download an image every time from the server, and then, i would like to change the number of images and/or their names. What do you propose for these requirements?

ps: I have been alerted for the Embed tag but it seems a little inconvenient in its use as you have to declare a new class for each asset and instantiate the class separately.

A: 

If you want to embed images, then you need to use the Embed tag, and the image files will be added to the builded swf. I do not understand how you want to have images embeded but load them from server or change their names? Once they are embeded you cannot rename or unload them. They will act like a hardcoded static variable.

If you want to dynamically load them from server then you just pass the url of the image to a mx:IMAGE source and there you have it...

Adrian Pirvulescu
Sorry for my English that make a confusion. I make an engine that will produce every time a different swf, according to some specifications. What i meant is that occasionally i'll have to support the engine with different graphics. So I'll have to modify a lot the folder that contains the graphics before each new building of the swf. I read your answer to this thread: http://stackoverflow.com/questions/1053546/howto-embed-images-in-actionscript-3-flex-3-the-right-way but i couldn't reproduce! Is it possible for you to make an example? Is it also possible to show me the fzip method too?
Specifically, i dont understand what do you mean by: myImage.source = Resource.SHIPS_1; in relation to the example that is presented in the thread, and how do i pass the Embed's zip which is instantiated by a MyZip:Class to an FZip constructor?
Then I am afraid that this is not possible... at least I don;t know a method of achieving it. :( sorry!
Adrian Pirvulescu
A: 

Hi

Met the problem above, the solution I use is a little straightforward, but simple. You write a batch file (.cmd) that goes through a directory, generating as3 code, then it runs the compiler to create .swf.

it looks something like this:

set target=a.as
@echo package { >%target%
@echo   import flash.display.Sprite; >>%target%
@echo   import flash.system.Security; >>%target%
@echo   public class %classname% extends Sprite{ >>%target%
@echo       Security.allowDomain('*'); >>%target%
for %%a in (*.png) do @echo         [Embed("%%~na.png")] public var %1_%%~na: Class; >>%target%
@echo       } >>%target%
@echo } >>%target%

it generates something like:

package { 
import flash.display.Sprite; 
import flash.system.Security; 
public class  extends Sprite{ 
Security.allowDomain('*'); 
        [Embed("a.png")] public var _beauty_nails: Class; 
        [Embed("b.png")] public var _club_dance: Class; 
        [Embed("c.png")] public var _club_date: Class; 
    } 
} 
poco