Sunday, April 6, 2008

Loading too many photos too fast!

On this project we have to load over 200 photos to the screen before the app should start. I was using a for loop to instantiate the Loaders, but kept finding sporadic results in loading. Sometimes all the photos would come in and other times only some of them would. Anyway, although I have nothing to prove it, I think it just was too much for flash to load so many things at once, so it would drop some as needed. In any event I decided to use a timer instead to do the loading:
public function addPhotosByTimer():void{
// the photo paths are stored in an array
var photoArrayLen:int = myPhotoArray.length;
// trigger the timer only for the number of items in the array
// and add a photo every 1oth of the sec
var photoAddTimer:Timer = new Timer(100,photoArrayLen);
var j:int = 0;
photoAddTimer.addEventListener(TimerEvent.TIMER,addPhoto);
photoAddTimer.start();

function addPhoto(evt:Event):void{
var photoLoader = new Loader();
var thisPath:String = thisSectPhotoArray[j];
photoLoader.load(thisPath);
j++;
}
}
So far it seems to work fine...

No comments: