Markus
Markus

Reputation: 687

Load External Image and Assign to a Symbol in Flash

I have a SWF file used as a banner advertisement but there is a 35kb size limit. My file is just under 60kb, and I won't be able to optimize the images any further. (An early version can be found here: http://cutthroat4x4.com/flash/)

I was thinking perhaps I could load 2 of my images dynamically?

I actually try to stay away from Flash and Actionscript, but had to use it for this advertisement. The animation is built with transitions and symbols in the timeline. That being said I know just enough actionscript to control the timeline / playback but not how to dynaimcally load images, then assign those images to the symbols I use in my animations.

Could someone hold my hand for about 5 minutes and give me the dummy 101 on how to dynamically load an image that a symbol will reference?

Not a permanent solution, but I discovered that I can make a simple pre-loader swf that has the background, and load the real swf using this simple actionscript code:

var myLoader:Loader = new Loader();        
var url:URLRequest = new URLRequest("http://cutthroat4x4.com/flash/cutthroat-advertisement.swf");
myLoader.load(url);
addChild(myLoader);

Upvotes: 2

Views: 1250

Answers (1)

felipemaia
felipemaia

Reputation: 3571

By just replacing the .swf path with the bitmap path, it should work: var url:URLRequest = new URLRequest("image.bmp");

If it doesn't, do this:

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
loader.load(new URLRequest("image.bmp"));

function onComplete (event:Event):void
{
    addChild(Bitmap(LoaderInfo(event.target).content));
}

Upvotes: 1

Related Questions