Preloading an array?

  • thegrrraue
  • Born
  • Born
  • thegrrraue
  • Posts: 3

Post 3+ Months Ago

So I've got an array of images,

Code: [ Select ]
pixArray = ["Images/Architecture/Hospitality/01.jpg", "Images/Architecture/Mixed/01.jpg", "Images/Architecture/Office/01.jpg", "Images/Architecture/Performing/01.jpg"];


It's part of a slide show, loading one image, waiting 4 seconds, then it loads another, etc etc. The problem is, between each image, it has to load.

I'm trying to find a way to get flash to keep loading all the images in the array until they're all loaded, something to the effect of:

on the completion of the loading of the first image, start loading the second image in the array. On completion of loading that, load the third image, etc, until there are no more. I already have a variable that tells it how many items there are as well:

Code: [ Select ]
var total:Number = 4;


Any ideas?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

Use the movieclip loader class to load the individual image files. In the onComplete call back for each load have a function that starts loading the next image in the sequence (make a container off the stage and then move the container to the proper location for the transition). In your function you need to test that current Img is less than array length (if so load next image, else stop the load)
  • thegrrraue
  • Born
  • Born
  • thegrrraue
  • Posts: 3

Post 3+ Months Ago

Ok, so I know how to use the movieclip loader, and I know how to use onComplete, but what I don't know is how to get it to call the next clip to be loaded. I mean, obviously it could be like

Code: [ Select ]
var myMCL = new MovieClipLoader();
myMCL1.loadClip("Image1.jpg", backgroundLoader);

myMCL1.onComplete = function() {
myMCL2.loadClip("Image2.jpg", backgroundLoader);
}
  1. var myMCL = new MovieClipLoader();
  2. myMCL1.loadClip("Image1.jpg", backgroundLoader);
  3. myMCL1.onComplete = function() {
  4. myMCL2.loadClip("Image2.jpg", backgroundLoader);
  5. }


But then that's sort of silly because I'm just coding out the whole thing by hand. I'd have to just do it for each individual image.

I have like 70 of these arrays in separate files, and it seems like there should be something I could put in each of them, the same code, that would check how many it had done against the "total" variable (which I'm not entirely sure how to do either), and tell it to advance to loading the next item in the array, whatever that may be.

Does that make sense?
  • thegrrraue
  • Born
  • Born
  • thegrrraue
  • Posts: 3

Post 3+ Months Ago

For anyone who finds this and needs an answer:

Code: [ Select ]
var preClip:MovieClip;
var preLoader:MovieClipLoader;
var preListener:Object;
var preList:Array;

function preload( imageList:Array ):Void
{
    var depth:Number = _root.getNextHighestDepth();
    
    preClip = _root.createEmptyMovieClip( "preClip", depth );
    preLoader = new MovieClipLoader();
    preListener = {
        onLoadInit: onLoaderInit
    };
    preList = [].concat( imageList );
    
    preLoader.addListener( preListener );
    preLoader.loadClip( preList[ 0 ], preClip );
}

function onLoaderInit():Void
{
    preClip._visible = false;
    preList.shift();
    
    if( preList.length )
    {
        preLoader.loadClip( preList[ 0 ], preClip );
    }
    else
    {
        preClip.removeMovieClip();
        preLoader.removeListener( preListener );
        
        preClip = null;
        preLoader = null;
        preListener = null;
        preList = null;
    }
}

preload( pixArray );
  1. var preClip:MovieClip;
  2. var preLoader:MovieClipLoader;
  3. var preListener:Object;
  4. var preList:Array;
  5. function preload( imageList:Array ):Void
  6. {
  7.     var depth:Number = _root.getNextHighestDepth();
  8.     
  9.     preClip = _root.createEmptyMovieClip( "preClip", depth );
  10.     preLoader = new MovieClipLoader();
  11.     preListener = {
  12.         onLoadInit: onLoaderInit
  13.     };
  14.     preList = [].concat( imageList );
  15.     
  16.     preLoader.addListener( preListener );
  17.     preLoader.loadClip( preList[ 0 ], preClip );
  18. }
  19. function onLoaderInit():Void
  20. {
  21.     preClip._visible = false;
  22.     preList.shift();
  23.     
  24.     if( preList.length )
  25.     {
  26.         preLoader.loadClip( preList[ 0 ], preClip );
  27.     }
  28.     else
  29.     {
  30.         preClip.removeMovieClip();
  31.         preLoader.removeListener( preListener );
  32.         
  33.         preClip = null;
  34.         preLoader = null;
  35.         preListener = null;
  36.         preList = null;
  37.     }
  38. }
  39. preload( pixArray );

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 18 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.