finlaybob
finlaybob

Reputation: 717

Acceptable way of loading multiple images in action script 3 with FlashDevelop / Flex

At work I've been asked to make a small web based mini-game prototype.

I went down the flash route and am using Flash Develop with Flex SDK.

I've also found a graphical framework and I can use that no problem, but I'm trying to make my own code reusable at a later date.

I have written a small class for loading a list of textures, from names supplied to the class before loading. It is here to keep the question concise.

To be honest when it comes to Flash/ActionScript, I have no idea what I'm doing, I only started using it a week ago.

What I want to know is whether my attempt is acceptable from a more experienced AS programmer's point of view. Is it really bad flash coding practice? Does flash handle garbage collection? Should I be keeping an eye on the new Loader() calls that I just disregard?

Upvotes: 1

Views: 570

Answers (1)

eleven
eleven

Reputation: 6847

First of all make loader as field of your class and reuse it. Then add error listener:

addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);

Also you should check input data:

public function addImage(fname:String):void {
    if(fname && fname != "") array.push(fname);     
}

When all images were loaded you should "reset" you loader:

array = [];

And it would be better if you will check the state of your loader to prevent unpredictable cases:

public function beginLoad():void {
   if(state == ALREADY_LOADING) return;
   count = 0;
   loadImages(count);
}

ps immutable fields such as loader, map, array mark const. It's not mistake but other developers will know that these fields are immutable.

Upvotes: 1

Related Questions