Jump to content


Progress Bar help required with "requireWithRoot"

Recommended Posts



First of all let me congratulate you on creating such an excellent product. I am using it currently, and I must say, its one of its kind and saves me so much time!!. Many thanks.


Here's the problem I am facing. Its not a bug at all, its just that I am unable to get it to function the way that I want it to.


I have a parent file called "index.swf". In this upon a click of a button, I am trying to load another SWF called, lets say "child.swf".


Please keep in mind that child.swf loads an XML file which has images. I am using loaderMax within child.swf to preload my XML and its images as well. Works great. The child.swf loader queue has "requireWithRoot" set properly, and it does function as advertised with the index.swf file.


The problem I am facing is that there is a "PRELOADER BAR" in my index.swf, which scales up (on x) as it loads the child.swf. The issue is that first it loads the child.swf and it scales up to 100%, when it does so. All good so far. But, now when it starts to load the XML and the images of the child.swf, it shoots back to 0%, and then it progresses again.


Where i need help is that the preload bar should show cumulative progress, rather than jumping to 100% first and then shooting back to 0% and then jumping to 100% again. Its very confusing for the end user.


Is this something that you can help me with?. Again, any help would be greatly helpful. I am posting snippets of code below, maybe it can help. I cannot post the files here, since they are mostly complete.





			var queue:LoaderMax = new LoaderMax({name:"mainer", onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler});

		queue.prepend( new SWFLoader("child.swf", {name:"mainClip", container:cHolder, x:0, autoPlay:false}) );

		function progressHandler(event:LoaderEvent):void {
			faderBox.loadBar.scaleX =  event.target.progress;
			trace("progress: " + event.target.progress);
		function completeHandler(event:LoaderEvent):void {
			loaded = true;
			TweenLite.to(faderBox.loadBar, 0.6, {scaleX:0, ease:Expo.easeOut});
			TweenLite.to(faderBox.header, 2, {y:10, ease:Expo.easeOut});
			TweenLite.to(faderBox.lineTop, 2, {y:faderBox.header.height , ease:Expo.easeOut});
			TweenLite.to(faderBox.lineBottom, 2, {y:stage.stageHeight- 30 , ease:Expo.easeOut});
		function errorHandler(event:LoaderEvent):void {
			trace("error occured with " + event.target + ": " + event.text);





		var queue:LoaderMax = new LoaderMax({name:"mainQueue", requireWithRoot : this.root, onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler});
		var picCount:Number = 0;
		var req:URLRequest = new URLRequest("XMLS/works.xml");
		queue.append( new XMLLoader(req, {onInit:processXML}) );
		var works:XMLList;
		var workstotal:Number;
		function processXML(e:LoaderEvent):void {
			var myXML:XML = new XML(e.target.content);
			works = myXML.work;
			workstotal = works.length();
			numRows = 2;
			numCols= Math.ceil(workstotal/numRows);
			trace("Number of Rows : "+ numRows +" , Number of Columns : " + numCols);
			for (var i:Number = 0; i < works.length(); i++) 
				picturePath = works[i].@thmb.toString();
				subPicArray.push(new Array());

				subPicArray[i][0] = works[i].@scr1.toString();; 
				subPicArray[i][1] = works[i].@scr2.toString();; 
				subPicArray[i][2] = works[i].@scr3.toString();; 
				subPicArray[i][3] = works[i].@scr4.toString();; 

				h1[i] = works[i].@title1.toString();
				h2[i] = works[i].@title2.toString();
				queue.append( new ImageLoader(picturePath, {name:"photo" + i, scaleMode:"proportionalInside"}) );


		function progressHandler(event:LoaderEvent):void {
			trace("progress: " + event.target.progress);
		function completeHandler(event:LoaderEvent):void {


And by the way, the XML is a straight forward XML, not a specific Loader MAX XML. Hope this makes sense.


If you need further information, please do let me know, I will be happy to provide it. Thanks a million for all the help and the product!!. Cheers.

Link to comment
Share on other sites

The problem: It is impossible for the parent swf to know how big the subloaded files inside the XML file are going to be (before loading the XML and auditing the files), so it's impossible to accurately report its progress without that data.


The solution: All you need to do is set the estimatedBytes of your XMLLoader as though it includes all of the nested objects. Like if your XML file itself is 1000 bytes but it loads 19000 bytes worth of images, you'd set the XMLLoader's estimatedBytes to 20000. Same goes for the SWFLoader - set estimatedBytes so that it includes all of the subloading stuff as well.

Link to comment
Share on other sites

Hi Jack,


Thank you so much for writing back to me. It seriously means a lot to each one of us posting our problems here!!.


Regarding your solution, in fact I was trying things out and constantly searching your forums, I did stumble upon a similar issue with some one else.


I have tried issuing the estimated number of bytes in the SWF loader, and it seems to work well, but I will also try the estimated bytes in the XML loader as well.


I will let you know how things are progressing.


By the way, if you want to have a look at what I was creating, please do check your PM. I am sending across a link. Please do let me know how you find it. Would love to hear your thoughts on it!!.


Again, greensock rocks!!. Tweenlite and TweenMax have saved my life more than just once. :D






Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.