Jump to content
Search Community

Progress Won't Integrate?

stompwampa test
Moderator Tag

Recommended Posts

I'm having a hard time getting loading progress to interate together.

 

In my LOADER swf, I have a SWFLoader that is loading my main movie.

 

Inside my main movie, I have a LoaderMax instance which loads a single XMLLoader (which subsequently creates a bunch of ImageLoaders).

 

Anyways...I've got it so that my main movie doesn't actually start until all loading is complete (which is good). But my LOADER swf first loads the main movie (and show's it's progress) then it starts the progress over back at 0 and shows the subloading of the LoaderMax/XMLLoader inside.

 

I want it all to work together as one big load...what am I missing?

 

Here is the code in my Loader file:

 

import com.greensock.loading.LoaderMax;
import com.greensock.loading.SWFLoader;
import com.greensock.events.LoaderEvent;

var loader:SWFLoader = new SWFLoader("MyMovie.swf",{name:"MyMovie",container:this,x:0,y:0,onComplete:onCompleteHandler,onProgress:onProgressHander,onError:onErrorHandler});

loader.load();

function onProgressHander(Event:LoaderEvent):void {

loading_txt.text = "Loading " + String(Math.ceil(Event.target.progress * 100)) + "%";
}

function onCompleteHandler(Event:LoaderEvent):void {

//addChild(loader.getContent("MyMovie"));
}

function onErrorHandler(Event:LoaderEvent):void {

loading_txt.text = "Error Loading Data.";
}

 

And here is the loading code in my main movie:

 

LoaderMax.activate([imageLoader]);

var xmlLoader:XMLLoader = new XMLLoader("xml/images.xml",name:"xmlLoader",onProgress:progressHandler,onComplete:completeHandler,onError:errorHandler});

var q:LoaderMax = new LoaderMax({name:"mainLoader",autoLoad:true,requireWithRoot:this.root});

q.append(xmlLoader);

Link to comment
Share on other sites

In the swf that you're subloading, is that LoaderMax instance created immediately (on the first frame or in your document class's constructor)?

 

Are you using the latest version of LoaderMax? http://www.greensock.com/loadermax/

 

Is "this.root" resolving to a valid value other than null?

 

Are you subloading across domains without a valid crossdomain.xml file in place?

 

Lastly, if none of these point you in the right direction, feel free to post an FLA (and support files) that demonstrates the issue so we can publish it ourselves and see what's happening.

Link to comment
Share on other sites

Yep. The LoaderMax is in the first frame of my movie.

 

this.root traces out to Object MainTimline.

 

I am NOT loading across a subdomain. Same directory actually.

 

Just upgraded to the latest version.

 

Still have the same issue. I guess it's not really THAT big of a deal...just kinda annoying for the user to see the progress bar shoot up to 100% and then start over again when the subloader starts it's load.

Link to comment
Share on other sites

Oh, I see the issues - you didn't define an estimatedBytes for your XMLLoader. See, the issue is that before the XML loads, LoaderMax has absolutely no way it could possibly know what's inside the XML and how big those files are going to be. Since you didn't define an estimatedBytes value for the XMLLoader, its progress simply reports based on the XML file itself initially. For example, the XML file may be 2000 bytes. But once it loads the full XML file and discovers that there are a bunch of nested loaders in there that represent another 500000 bytes worth, the progress value will suddenly shrink for obvious reasons.

 

The estimatedBytes value for the XMLLoader should include the subloading files. So if the XML file is 2000 bytes and it has 500000 bytes worth of images it will load (or whatever), the XMLLoader's estimatedBytes would be 502000.

Link to comment
Share on other sites

I'm having the same (or very similar problem). I actually can't see how it could actually even work, unless I'm missing something.

 

I have a small preloader SWF. It uses a SWFLoader to load a "main" SWF (let's call it MAIN). It has an estimatedBytes set to the actual size of MAIN. The MAIN swf is built in FlexBuilder and is just all actionscript. Its runnable class (document class) has a constructor that instantiates a bunch of SWF loaders and starts them loading, e.g. call them SWFA, SWFB, SWFC. All loaders have estimatedBytes set.

 

When the preloader loads and starts the loading of MAIN, I get progress events from 0 to 0.99xxxxx *BEFORE* the constructor of MAIN is even called. So how could the progress of SWFA, SWFB, and SWFC be integrated? Those SWFLoaders aren't even created until MAIN has essentially completed loading.

 

Am I doing something wrong? Is it because my SWFs are compressed?

 

The only way I've got it to kind of work (and this is NOT what I'd ideally want to do), is set the estimatedBytes of the MAIN SWFLoader to be equal to the size of MAIN + SWFA + SWFB + SWFC.

 

E.g. I think for the original poster, the only way it will work is to set the estimatedBytes of his first SWFLoader to be (size of main movie + estimatedBytes of the XMLLoader). This isn't idea because the LOADER shouldn't need to know the size of all the subloaded SWFs...

 

Ideas? Thoughts?

 

Greg

Link to comment
Share on other sites

You are exactly correct - the only conceivable solution is to make the estimatedBytes of the main SWFLoader include the ones that will be subloaded too (inside that swf). Otherwise, how could LoaderMax possibly know what to expect inside there? It's absolutely impossible. But again, that's why estimatedBytes exists. That's the solution. Sure, it'd be great if LoaderMax could magically know the sizes of even the files that it hasn't discovered it will need to load yet, but I'm pretty sure nobody can figure out a way to make that happen :)

 

Does that answer your question?

Link to comment
Share on other sites

Yes, thanks, that was what I suspected. The docs had led me to believe that somehow, if I loaded a SWF A with SWFLoader, that SWF A's constructor would be called very early on in the loading (e.g. after the onInit event was dispatched), so SWFLoaders within A's constructor would be identified and their estimated bytes added to the overall total... And yes, it did seem like it must be magic :)

 

One tip I have is:

 

Let's say you are going to use an XMLLoader in a preloader, and you don't know how many bytes will ultimately be loaded by the loaders in the XML file. So you can't really set an estimatedBytes value for the XMLLoader, and besides, you don't want to keep changing your preloader code just to change the estimated bytes value (of course, you could pass it in as a flash var, but let's say you don't do that).

 

If you don't have an estimatedBytes for the XMLLoader, the XML file itself will load very quickly (since it will likely be very small), and you'll get a progress event right away of something like 0.9883243. Then the loaders defined in the XML file will start loading and you'll get progress events starting back near 0. So, since the XML file is small and likely a very small percentage of the overall loading, what you can do is have an onInit handler for the XMLLoader, and in that handler set an "xmlParsed" flag to true. Then simply don't report progress/update your progress bar until xmlParsed is true...

Link to comment
Share on other sites

In regards to my original post...does it matter if the SWF file I am subloading uses a LoaderMax which inturn loads an XMLLoader or if I just skip the LoaderMax and create an XMLLoader right onto the stage and use that? (in terms of estimatedBytes being sent back to the LOADER swf file)

Link to comment
Share on other sites

In regards to my original post...does it matter if the SWF file I am subloading uses a LoaderMax which inturn loads an XMLLoader or if I just skip the LoaderMax and create an XMLLoader right onto the stage and use that? (in terms of estimatedBytes being sent back to the LOADER swf file)

Yes, it does matter - if you don't use a LoaderMax-related loader, it can't be integrated into the progress of the parent loader. SWFLoader and XMLLoader both only use their estimatedBytes until they've loaded enough of their content to search for LoaderMax-related stuff. Once that is done, it corrects its bytesTotal accordingly and proceeds. So if you're only using a URLLoader or something that's not LoaderMax-related, its progress won't be integrated.

Link to comment
Share on other sites

What I meant was that is it necessary to create a LoaderMax on my sub-loaded swf to load my XMLLoader if my XMLLoader in turn has a LoaderMax node followed by several ImageLoader nodes? Or can I just skip the first LoaderMax on Frame 1 and just use an XMLLoader and it's subsequent LoaderMax/ImageLoaders?

Link to comment
Share on other sites

No, you don't need to tuck your XMLLoader into a LoaderMax instance if you don't want to. The only benefit to nesting things in a LoaderMax instance is if you have more than one loader that you want to load in sequence or if you want to report on multiple loaders' progress as a whole. You can use any loader type independently if you want. XMLLoader will automatically integrate stuff it discovers inside its XML into its own loading progress (it creates a LoaderMax internally, but that's all transparent to you).

Link to comment
Share on other sites

  • 1 year later...

 

Let's say you are going to use an XMLLoader in a preloader, and you don't know how many bytes will ultimately be loaded by the loaders in the XML file. So you can't really set an estimatedBytes value for the XMLLoader, and besides, you don't want to keep changing your preloader code just to change the estimated bytes value (of course, you could pass it in as a flash var, but let's say you don't do that).

 

If you don't have an estimatedBytes for the XMLLoader, the XML file itself will load very quickly (since it will likely be very small), and you'll get a progress event right away of something like 0.9883243. Then the loaders defined in the XML file will start loading and you'll get progress events starting back near 0. So, since the XML file is small and likely a very small percentage of the overall loading, what you can do is have an onInit handler for the XMLLoader, and in that handler set an "xmlParsed" flag to true. Then simply don't report progress/update your progress bar until xmlParsed is true...

This is a good solution

 

Unfortunately I have a few XML files which are linked together via one XML file, in a series of XMLLoaders

 

Is it possible to create a handler that waits for all the child XML's to finish loading too? Something like onChildInit ?

Link to comment
Share on other sites

Hi Friendly Giraffe,

 

I'm having a tough time understanding how your files are set up.

You can give each XMLLoader in your LoaderMax the same onInit event handler function. That function could then assess how many xml files have fired their init events.

 

something like:

 

var xmlLoadedCount :int= 0;
var xmlLoadedMax:int = myLoaderMaxThatContainsMyXMLLoaders.numChildren;

function xmlInitHandler(e:LoaderEvent):void{
xmlLoadedCount++;
if (xmlLoadedCount == xmlLoadedMax){
trace("all xml files have fired init");
}
}

 

the following code assumes that your LoaderMax only contains XMLLoaders.

 

c

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.
×
×
  • Create New...