Hi guys,
I am not sure if it’s the good place to post this…
I posted a tread last week about a preloader to load and cache multiple files (swf) that are at different addresses before playing a flash page. Someone finally posted an answer, and the code is almost working perfectly. The way to make it work is by having an .html file, an .as file and a .swf loader file.
The issue is with the .as file using fileURLArray.push. i entered 10 addresses to load and cache 10 files but it’s stopping after 5 preload or caching. Any ideas why it’s only preloading 5 instead of 10 ?
Test address; http://www.liferevolution.com/test2/
Script;
package {
import flash.display.Loader;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.net.URLRequest;
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
/**
* @author Max Galliano
* @date 12.12.2009
*/
public class Preloader extends MovieClip {
private var fileURLArray:Array=[];
private var fileToLoad:String;
private var mainLoader:Loader;
private var loadinCounter:Numner=0;
private var loaded:Numner=0;
public function Preloader() {
stage.scaleMode=StageScaleMode.SHOW_ALL;
stop();//stop the main timeline
//here you catch the url from outside, given by flashvars as 'fileToLoad'
//http://www.domain.com/wherever/main.swf
fileToLoad=this.stage.loaderInfo.parameters["fileToLoad"];
fileURLArray.push("main.swf");
fileURLArray.push("http://www.liferevolution.com/about/main.swf");
fileURLArray.push("http://www.liferevolution.com/enroll_requestcoach/main.swf");
fileURLArray.push("http://www.liferevolution.com/homepage/main.swf");
fileURLArray.push("http://www.liferevolution.com/lifecoaching/main.swf");
fileURLArray.push("http://www.liferevolution.com/links/main.swf");
fileURLArray.push("http://www.liferevolution.com/referral/main.swf");
fileURLArray.push("http://www.liferevolution.com/signup/main.swf");
fileURLArray.push("http://www.liferevolution.com/thebuzz/main.swf");
fileURLArray.push("http://www.liferevolution.com/unlock/main.swf");
fileURLArray.push("http://www.liferevolution.com/workshops/main.swf");
loadMain();
}
private function loadMain():void {
mainLoader = new Loader();
mainLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onMainComplete);
mainLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);
mainLoader.load(new URLRequest(fileToLoad));
}
private function onProgress(event : ProgressEvent):void {
//if you have a 100 Keyframe Preloader Animation on the Main Timeline
//Frame 100 empty
//you can do the following:
var perc:Number=int(event.bytesLoaded/event.bytesTotal*100);
gotoAndStop(perc);
}
private function onMainComplete(e : Event):void {
mainLoader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, onProgress);
mainLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onMainComplete);
addChild(mainLoader.content);
//now you can load all other files for chaching
preload();
}
private function preload():void {
var loader:Loader;
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
for (var i : int = 0; i < fileURLArray.length; i++) {
if (_loadingCounter<fileURLArray.length) {
loader = new Loader();
loader.load(new URLRequest(fileURLArray*));
}
_loadingCounter++;
}
}
private function onComplete(e : Event):void {
e.target.removeEventListener(Event.COMPLETE, onComplete);
loaded++;
if (loaded==5) {
loaded=0;
preload();
}
}
}
}
Thanks in advance !!!