Hi Carl and thanks again for your help!
I have rewritten the code with SelfLoader but I know you can do better...
I would like to ask you a few things:
- When I click on a button I unload the queue of LoaderMax, is the right thing to do?
- Why the total_bar seems to start loading from the middle of the line? Is there a way to have a more linear animation?
- Why I receive "progress: 0" when I click on a button? This is contained in progressHandler() and not in child_progressHandler()
This is a files link: http://we.tl/RshuyeKD0F
Thanks!
package {
import flash.display.MovieClip;
import flash.events.*;
import flash.display.*;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;
public class main extends MovieClip {
var queue:LoaderMax = new LoaderMax({name:"mainQueue", onInit:initHandler, onProgress:progressHandler, onComplete:completeHandler});
var loader_child:SWFLoader = new SWFLoader("",{onInit:child_initHandler, onProgress:child_progressHandler, onComplete:child_completeHandler, container:this, x:100, y:50});
public function main() {
// constructor code
init_totalLoader();
var swf:Array = new Array(works,about,contact,home);
for (var i:int=0; i<swf.length; i++) {
swf[i].addEventListener(MouseEvent.CLICK, openSwf);
swf[i].visible=false;
}
child_bar.visible=false;
}
public function init_totalLoader() {
//append the SelfLoader and several other loaders
var loader:SelfLoader = new SelfLoader(this, {name:"self"});
queue.append( loader );
queue.append( new SWFLoader("swf/home.swf", {name:"home", container:this, x:100, y:50}) );
//start loading the LoaderMax queue
queue.load()
}
function openSwf(e:MouseEvent): void{
var newURL:String = "swf/" + e.target.name + ".swf";
loader_child.url = newURL;
loader_child.load(true); // reload SWFLoader and flush/unload old content
}
///////////////////TOTAL LOADER FUNCTIONS///////////////////////////
public function initHandler(event:LoaderEvent):void {
total_bar.visible=true;
}
public function progressHandler(event:LoaderEvent):void {
percent.text=String(Math.floor(event.target.progress*100))+"%";
total_bar.totalprogress.scaleX = event.target.progress;
trace("progress: " + event.target.progress);
}
public function completeHandler(event:LoaderEvent):void {
trace(event.target + " is complete!");
percent.visible=false;
child_bar.visible=true;
total_bar.visible=false;
home.visible=true;
works.visible=true;
contact.visible=true;
about.visible=true;
}
///////////////////CHILD LOADER FUNCTIONS///////////////////////////
public function child_initHandler(event:LoaderEvent):void {
queue.unload()
}
public function child_progressHandler(event:LoaderEvent):void {
child_bar.childprogress.scaleX = event.target.progress;
}
public function child_completeHandler(event:LoaderEvent):void {
}
}
}