Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Preloading assets

New Here ,
Mar 26, 2014 Mar 26, 2014

Hi,

I'm making a flash app for the web and have a lot of images and sound in it. I would like to preload these assets before the program loads so that the program runs smoothly without having to load assets on the spot

Here's my code:

function preLoader():void

{

          for(var i:int = 1; i <= 6; i++)

          {

                    for(var j:int = 1; j <= (this["array"+i][0].length)-1; j++)

                    {

                              snd1 = new Sound(new URLRequest(this["array"+i][0]));

  snd1.addEventListener(Event.COMPLETE, preLoadComplete);

  image1.url = this["array" + i][1];

                              imageLoader1.load(image1);

  imageLoader1.contentLoaderInfo.addEventListener(Event.COMPLETE, preLoadComplete);

                    }

 

          }

}

function preLoadComplete(e:Event):void

{

          count++;

  if(count == totalAssetNo)

   {

     init();

   }

}

All the paths for the images and sounds are stored in arrays.

The sounds preload fine but the images don't. The images only call the preLoadComplete function once in total not once each time something has loaded

Is this the correct way of preloading?

How can I correctly preload the images?

Cheers

Chris

TOPICS
ActionScript
307
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 26, 2014 Mar 26, 2014

you need to wait until loading is complete for each image before starting to load the next image because a loader can only load one item at any one time.  ie, remove those for-loops and manually increment i and j in preloadComplete.

Translate
Community Expert ,
Mar 26, 2014 Mar 26, 2014
LATEST

you need to wait until loading is complete for each image before starting to load the next image because a loader can only load one item at any one time.  ie, remove those for-loops and manually increment i and j in preloadComplete.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines