3

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.

user922467
  • 35
  • 5

3 Answers3

2

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.

kapex
  • 28,903
  • 6
  • 107
  • 121
  • The application is a test for children. Mostly all of the resources will be needed, but some may not be used due to branching in the program. Most resources are 20 - 200 kb. Right now my total resources are around 12MB, but that is expected to reach upwards of 50 - 70 MB by the completion of the application. – user922467 Nov 24 '11 at 17:07
  • 1
    @user922467 That is to much for preloading imho, especially if it will grow. I would probably try to load resource for the upcoming question(s) while the user is answering the current one. Could be a problem if the next question depends on the current questions answer... either let the user wait or let him load stuff he isn't going to need. That's for you to decide. – kapex Nov 24 '11 at 17:19
  • Thanks for your help. I will try to preload a few questions ahead. – user922467 Nov 24 '11 at 17:23
1

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).

Boundless
  • 2,444
  • 2
  • 25
  • 40
0

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;
  ....
Mahmut C
  • 427
  • 4
  • 6