Jump to content
Search Community

LoaderMax onError Remove

bartpop test
Moderator Tag

Recommended Posts

I'm trying to determine how to remove an XMLLoader from the LoaderMax queue when the XMLLoader encounters an error. I've set-up an onErrorHandler to use the LoaderMax.remove method, but can't determine the syntax to target the XMLLoader that threw the error. Here's what I'm trying:

 

private function onXMLError (e:LoaderEvent) :void{
		_XMLLoader.remove(e.target);
	}

 

But the e.target code returns "null". I should point out that "_XMLLoader" is my LoaderMax queue. Does anyone know what I'm missing?

Link to comment
Share on other sites

Are you sure e.target returns null? That shouldn't be the case - I'd totally appreciate it if you'd post an example FLA that demonstrates the issue (as simple as possible please).

 

The event's target should always point to the related loader instance, so your code looks correct to me.

Link to comment
Share on other sites

I tried this code:

import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.events.*;

var _myLoader:LoaderMax = new LoaderMax({name:"XMLQueue", onError:onXMLError});
_myLoader.append(new XMLLoader("http://www.fakesite.com/fake.php", {name:"myFakeXML"}));
_myLoader.load();

function onXMLError (e:LoaderEvent) :void{
trace("onXMLError() : " + e.target);
//_myLoader.remove(e.target);
}

 

In the onXMLError function, the trace result is:

onXMLError() : XMLLoader 'myFakeXML' (http://www.fakesite.com/fake.php)

 

but uncommenting the _myLoader.remove(e.target); line results in the following error:

1118: Implicit coercion of a value with static type Object to a possibly unrelated type com.greensock.loading.core:LoaderCore.

 

I can force the remove method to work by adding this code:

_myLoader.remove(e.target as XMLLoader);

 

But that's impractical if I don't know what kind of loader is throwing the error.

Link to comment
Share on other sites

_myLoader.remove(e.target as LoaderCore);

 

I gave that a shot but got the following errors:

 

1120: Access of undefined property LoaderCore.

1118: Implicit coercion of a value with static type Object to a possibly unrelated type com.greensock.loading.core:LoaderCore.

Link to comment
Share on other sites

Is there a quick explanation as to why the e.target object needs to be cast as LoaderCore? I compulsively like to know how things work.

 

Because the remove() method expects a LoaderCore object as the parameter you pass it. If you pass it something that isn't typed as a LoaderCore, Flash complains.

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