Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
Lixus

LoaderMax onComplete strange behavior

Recommended Posts

Hey,

 

First of all: Thank you for this absolutely great loading class, i was blasted away when i found this! (And remembered all the headaches i had over preloading in my previous projects :mrgreen: )

 

I've got one problem with my recent project though: I'm loading multiple images and videos. Some of them may not be on the server at the time the script looks for them (Which is perfectly OK with me - i just try to load them and if not i skip the slides in which they are). I have listeners for onComplete and onError. If one of the images in my queue cannot be loaded, the error is thrown correctly. Still, the onComplete Event fires! Is this a bug or a feature or did i do or understand something wrong?

 

Here is the fragment of code with the loaders:

public function loadContent():void
{
loader = new LoaderMax( { name: "content_loader", onComplete: onLoadContentComplete, onError: onLoadContentError } );
for each(var element:XML in xml.elements()) {
	switch (element.name().localName) {
		case "img":
			loader.append(new ImageLoader(Main.URL_MEDIA + element.@src, { name: element.@src, x: element.@xpos, y: element.@ypos, width: element.@width, height: element.@height } ));
			break;
		case "vid":
			loader.append(new VideoLoader(Main.URL_MEDIA + element.@src, { name: element.@src } ));
			break;
	}
}
loader.load();
}

 

Thank you in advance,

Cheers,

Felix

Link to comment
Share on other sites

That's actually not a bug - by default, a LoaderMax will dispatch its COMPLETE event when it's done going through its queue regardless of whether or not there were any errors or failures in any of its children. Notice, however, that a LoaderMax has two properties that may be of interest to you, and they're both set to true by default: skipFailed and skipPaused. If you want the LoaderMax instance to stop immediately whenever one of its children fails to load, and consider itself "failed" in that scenario, simply set skipFailed to false. Obviously skipPaused does the same thing when it encounters paused children.

 

Does that clear things up?

 

Most developers seem to want LoaderMax to keep on chuggin' even if one of its children fails, and keep in mind that you can always listen for the LoaderMax's CHILD_FAIL events too. Hopefully you'll find that there's tons of flexibility in the LoaderMax system that'll give you what you need for virtually any loading task.

Link to comment
Share on other sites

Hay, thanks for your super-fast answer!

 

I just noticed that in another class in the same project i need exactly the other behavior - firing the COMPLETE even if not all loaders succeed... :D

But this helps, actually. I'll just set skipFailed, this seems to be exactly what i'm looking for.

Thank you again!

 

Felix

Link to comment
Share on other sites

  • 3 months later...

Hi,

 

I'm just getting to grips with LoaderMax. It's another amazing tool, as always.

I have a similar question to the one above. I have a a LoaderMax with a few loaders in it's queue. One of those loaders is an XMLLoader, which contains another LoaderMax node that's set to load automatically.

Is there a way to detect a CHILD_FAIL event from the LoaderMax contained in the xml, as it doesn't seem to work?!

Also, does skipFailed work recursively, that is if I set it in the top most LoaderMax would it pick up a failed asset in a nested LoaderMax?

 

Thanks in advance!

 

Please see my code below for reference.

var loaderMax : LoaderMax = new LoaderMax({onComplete: onComplete, onProgress: onProgress, onError: onError, skipFailed: false});
loaderMax.addEventListener(LoaderEvent.CHILD_FAIL, onError);
loaderMax.append(new SWFLoader('main.swf'));
loaderMax.append(new XMLLoader(xml/main.xml'));
loaderMax.load();

Link to comment
Share on other sites

Yes, the LoaderMax instance will dispatch CHILD_FAIL events when any of its children (or grandchildren, etc.) fail. In other words, failure events bubble up the chain. I just tested it myself the way you described and it worked perfectly. I put a node in an XML file that was loaded with an XMLLoader and I purposely put a bogus url in place. The CHILD_FAIL event was properly dispatched from both the XMLLoader and the parent LoaderMax instance. If you don't think it's working, would you please post an example that I can publish and see the problem for myself?

 

As far as skipFailed goes, it's not recursive (nor should it be - I think that'd be rather odd). So you can tell each LoaderMax individually how you want it to handle failures (skip them or not). And by the way, skipping them doesn't mean that it won't dispatch CHILD_FAIL events - it will. If skipFailed is true, it just allows the queue to continue on after a failure occurs. If you want the LoaderMax to immediately stop and consider itself to have failed as soon as one of its children fails, then set skipFailed to false. That's pretty uncommon, though.

 

Oh, and please make sure you're running the latest version of LoaderMax. http://www.LoaderMax.com

 

Does that answer your question(s)?

Link to comment
Share on other sites

That does indeed.

 

Bit of rookie error I'm afraid, the in the test I had set up I was using a VideoLoader as the child that would fail, without actually having the VideoLoader enabled in the code. Is there a way of catching that? Although I'm pretty sure I'll remember it from now on, but perhaps some sort of verbose debugging feedback? Also, what you said about skipFailed makes perfect sense, thanks for clearing that up.

 

Thanks for getting back to me so quickly too.

 

-T.

Link to comment
Share on other sites

Bit of rookie error I'm afraid, the in the test I had set up I was using a VideoLoader as the child that would fail, without actually having the VideoLoader enabled in the code. Is there a way of catching that?

Could you explain a bit further what you mean? You commented out your VideoLoader line and you want LoaderMax to have a feature that would tell you that?

Link to comment
Share on other sites

Hi,

 

What I mean is that I didn't activate VideoLoader in my code, LoaderMax.activate([xmlLoader, SWFLoader]);, so when I added a VideoLoader to the xml it didn't load. What I was asking, is if you try to load something through a loader type you have not activated, will it just silently skip over that loader, or is there a way to pick this up?

 

I hope that makes a bit more sense.

 

-T.

Link to comment
Share on other sites

Oh, I see what you're saying. Well, that certainly wouldn't be impossible to add to XMLLoader, but I'm not sure it would be wise. There would be a file size cost (not the end of the world) but more importantly I'm not sure how to implement the warning other than a trace() which you'd only see during development. I wouldn't want to throw an error because there very well may be cases where developers purposely don't activate a type of loader and it really shouldn't throw errors in that case. See what I mean? You could certainly create your own class that looks at the XML from your XMLLoader and looks through the nodes.

 

Were you just looking for a trace() warning? Got any better ideas?

Link to comment
Share on other sites

Yes, traces would be fine. It would be pretty straight forward to create my own util that handles that, as you suggested, so don't worry about it.

 

Thanks for you help!

 

I have a new issue though, it might be best to create a new thread but I'll add it here for now, let me know if you'd prefer me to move it somewhere else.

 

I'm getting:

 

SecurityError: Error #2142: Security sandbox violation: local SWF files cannot use the LoaderContext.securityDomain property.

 

when I try to load an asset swf through an xml SWFLoader with it's context set to 'own'. I'll be grabbing assets out of the loaded swf with getDefinitionByName. Can you point me in the right direction please?

 

Cheers,

 

-T.

Link to comment
Share on other sites

Ah yes, good catch - Flash chokes when you try loading stuff locally and set the SecurityDomain (silly if you ask me). I just uploaded an update to LoaderMax that should fix the issue. Please check it out and let me know if it works okay for you.

Link to comment
Share on other sites

Jack, you're a legend! Thank you very much for your help, that worked a treat. Your commitment to helping people out never ceases to amaze, cheers bud.

 

-T.

Link to comment
Share on other sites

  • 5 months later...

Hi Jack,

 

Ok I am also puzzled by onComplete behavior working with "skipFailed" variable. Here is the xml:

 






Here is the XMLLoader instantiation:

 

this.xmlLoader = new XMLLoader (new URLRequest (this._xmlData.getComponentInfoPHP.@path),
{
name: 'dataLoader',
onComplete: this.onComplete,
onError: this.onError,
onIOError: this.onIOError,
onFail: this.onFail,
onChildProgress: this.onChildProgress,
onChildComplete: this.onChildComplete,
onChildFail: this.onChildFail,
skipFailed: false,
skipPaused: false,
noCache: true
});

 

You see! I have added "skipFailed" (and even "skipPaused") to both the XML's node as well as in the XMLLoader instantiation, yet the still fires even after a child has failed to load. Pretty sure that I must have done something stupid, but still; help please!

 

Thanks,

- Tahir.

Link to comment
Share on other sites

The latest version of XMLLoader recognizes "skipFailed" in its vars. Sorry about any confusion that caused.

Link to comment
Share on other sites

Hi Jack. Even after downloading the latest classes, I still have the same issue :(. I mean the still fires even after failure. I have the same structure of both XML's nodes as well as XMLLoader instantiation bit as before.

Link to comment
Share on other sites

Hi Jack. Even after downloading the latest classes, I still have the same issue :(. I mean the still fires even after failure. I have the same structure of both XML's nodes as well as XMLLoader instantiation bit as before.

You have skipFailed:false on the XMLLoader? You're 100% positive you're using the latest version too? I tested it and it works fine on my end. Please post a very simple FLA that I can publish to see the issue.

Link to comment
Share on other sites

You know, it is working perfectly :). Apologies, I didn't download the latest. Jack! you rock. Thanks a lot.

 

- Tahir.

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.
×