Jump to content
  • Advertisement
Sign in to follow this  
eedok

refactoring image loading in actionscript 3

This topic is 3679 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a piece of actionscript code I'd like to clean up, it currently looks like this:
var bm1_loader:Loader = new Loader();
bm1_loader.contentLoaderInfo.addEventListener( Event.INIT,
function (e:Event)
{
	bm1 = Bitmap(bm1_loader.content).bitmapData;
	bitmapLoadSuccess();
});
bm1_loader.load(new URLRequest("assets/img/bm1.png"));
var bm2_loader:Loader = new Loader();
bm2_loader.contentLoaderInfo.addEventListener( Event.INIT,
function (e:Event)
{
	bm2 = Bitmap(bm2_loader.content).bitmapData;
	bitmapLoadSuccess();
});
bm2_loader.load(new URLRequest("assets/img/bm2.png"));
var bm3_loader:Loader = new Loader();
bm3_loader.contentLoaderInfo.addEventListener( Event.INIT,
function (e:Event)
{
	bm3 = Bitmap(bm3_loader.content).bitmapData;
	bitmapLoadSuccess();
});
bm3_loader.load(new URLRequest("assets/img/bm3.png"));

the bitmapLoadSuccess just updates the loading screen, so I'm just looking for a way to perhaps reduce this to:
bm1 = loadBMP("assets/img/bm1.png");
bm2 = loadBMP("assets/img/bm2.png");
bm3 = loadBMP("assets/img/bm3.png");
while having a magic loadBMP function that does the above, but my problem is, without passing by reference there's no way to dynamically set the bitmap to load, and because the load event is in an anonymous function I can't return it, so is there an optimal way of doing this? EDIT:forgot to add I tried this, and it does not work:
protected function loadBitmap(bitmap:BitmapData,path:String):BitmapData
{
	var loader:Loader = new Loader();
	loader.contentLoaderInfo.addEventListener( Event.INIT,
	function (e:Event)
	{
		bitmap = Bitmap(loader.content).bitmapData;
		bitmapLoadSuccess();
	});
	loader.load(new URLRequest(path));
	return bitmap;
}
[Edited by - eedok on May 28, 2008 11:34:11 AM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!