I want to embed some images at compilation time so I end up with just a single swf.
They need to be inside of an array as I need to modify them programatically and they can be 100s of images. Cant use flex as I want to keep the whole function in actionscript (aka make files smaller)
I found how to do it in flex:
... <mx:Array id="test"> <mx:Image id="image0" source="@Embed(source='../../../lib/Images033,jpg')" /> <mx:Image id="image1" source="@Embed(source='../../../lib/Images034,jpg')" /> <mx:Image id="image2" source="@Embed(source='../../../lib/Images035,jpg')" /> <mx:Image id="image3" source="@Embed(source='../../../lib/Images036,jpg')" /> </mx:Array> ... addChild(test as something); ...
So does anyone know how to do the above but just in Actionscript?
Well, one way or another, you're going to need an Embed statement for every thing you want to embed, so you won't really be able to get around that. But if you'd prefer to handle everything in script, you could do something like this (it's an AIR application, but everything between the WindowedApplication tags should work within a plain ol' Flex app):
So essentially what you're doing, after making sure your images are all embedded at compile time and named according to some numeric scheme (in this case, just appended with an index), is filling your array with Class references, then instantiating and adding them to the display list during the createChildren() phase of the component lifecycle.
There's some esoteric stuff going on here, so if you don't quite understand everything, feel free to comment back, and I'll keep an eye on things. But this is tested code and should work pretty well for ya, given how you've explained your requirements so far.