user922467
user922467

Reputation: 35

Flash AS3 loading best practices

I am creating an interactive flash application where I need to use many sound files and images. I am currently loading resources (both images and sound files) as I need them. When I run it on my computer everything works fine and I see no delay. Running it on an offsite computer shows pauses and delays. I know this is due to the time it takes to load the resources.

I want to know what the best practice for loading resources is. Should I preload everything in the beginning (which will create a considerable pause)? Is it better to have a short pause multiple times throughout when a new resource is needed? Or is there a better solution (I hope this is the case)?

I have been programming in AS3 for about 3 months so I am relatively new. I'm sorry if this question is really noob, but I do need to figure out what to do about the delays.

Upvotes: 3

Views: 394

Answers (3)

Mahmut C
Mahmut C

Reputation: 433

For preloading the resources I strongly recommend using Greensock library. Actually by using LoaderMax you can queue the content to be loaded and then attach the loaded content to the containers (movieclips, sprites etc.)

Here is a sample code for loading multiple resources:

var queue:LoaderMax = new LoaderMaxVars()
                .maxConnections(1)
            .onProgress(onContentProgress)
            .onIOError(onIOErrorHandler)
                            .onComplete(onContentLoaded));

queue.append(new SWFLoader(contentTobeLoaded,new SWFLoaderVars().name(loaderName)));

....

private function onEmployeeContentLoaded(event:LoaderEvent):void {
  var loadedContent:Array = (event.target as LoaderMax).content;
  ....

Upvotes: 0

Boundless
Boundless

Reputation: 2464

I agree with @kapep that you should pre-load commonly used resources at the beginning. If there are large resources that the user may not need you could load those on demand.

If this test is sequential you could load "test question 2" material right after "test question 1" starts. You can load asynchronously so the application is still interactive (user can interact with test question 1) while more material is being loaded (test question 2 resources).

Upvotes: 1

kapex
kapex

Reputation: 29999

It depends on what kind of application it is:
If you expect a user to go through your whole application anyway (like a game for example) you should do preload the resources. If your application is more like a media player or an image gallery where most users will only see a few resources, you should load resources on demand.

It also depends on how large the resources are. You shouldn't let users wait to long or create to much traffic. On the other hand it may be easier to do a single preload than loading each tiny resources in a single request. Maybe you coulddefine larger sets to in a single step to avoid this. You may even combine both methods: preload some common resources and load some other stuff in the background.

Upvotes: 2

Related Questions