Jump to content
GreenSock

scratch

Why onComplete always gets fired?

Recommended Posts

Hi,

 

the docs say (important part highlighted red):

 

onComplete : Function - A handler function for LoaderEvent.COMPLETE events which are dispatched when the loader has finished loading successfully. Make sure your onComplete function accepts a single parameter of type LoaderEvent (com.greensock.events.LoaderEvent).

 

Code:

//create a LoaderMax named "mainQueue" and set up onProgress, onComplete and onError listeners
lmaxMain = new LoaderMax({name:"lmaxMain",maxConnections:1,onProgress:onLMaxProgress,onChildComplete:onLMaxChildComplete,onComplete:onLMaxComplete,onError:onLMaxError});
//append several loaders
lmaxMain.append(new ImageLoader("logo.png", {name:"logo",estimatedBytes:3000,container:this,alpha:0,width:300,height:200,scaleMode:"proportionalInside"} ));
lmaxMain.append(new ImageLoader("intro.png1", {name:"intro",estimatedBytes:13000,container:this,alpha:0,width:800,height:600,scaleMode:"proportionalInside"} ));

//prioritize the loader named "intro"
LoaderMax.prioritize("intro",false);
LoaderMax.prioritize("logo",false);

//start loading
lmaxMain.load();
private function onLMaxProgress(event:LoaderEvent):void
{
trace("Main.onLMaxProgress - Progress: " + event.target.progress);
}

private function onLMaxChildComplete(event:LoaderEvent):void
{
trace("Main.onLMaxChildComplete - Name: " + event.target.name);
if(event.target.name == "logo")
{
 var image:ContentDisplay = LoaderMax.getContent("logo");
 image.x = stage.stageWidth / 2 - image.width / 2;
 image.y = stage.stageHeight / 2 - image.height / 2;
 TweenNano.to(image,1,{alpha:1});
 trace("Main.onLMaxChildComplete - Logo added to screen.");
}
}

private function onLMaxComplete(event:LoaderEvent):void
{
trace("Main.onLMaxComplete - Complete: " + event.target + " is complete!");
}

private function onLMaxError(event:LoaderEvent):void
{
lmaxMain.cancel();
trace("Main.onLMaxError - Error: " + event.text);
}

 

Output:

Main.onLMaxProgress - Progress: 0.18505516549648948
Main.onLMaxChildComplete - Name: logo
Main.onLMaxChildComplete - Logo added to screen.
Main.onLMaxProgress - Progress: 1
[color=#FF0000]Main.onLMaxComplete - Complete: LoaderMax 'lmaxMain' is complete![/color]
----
Error on ImageLoader 'intro' (intro.png1): Error #2035: URL not found. URL: file:///C|/intro.png1
----
Main.onLMaxError - Error: ImageLoader 'intro' (intro.png1) > Error #2035:URL not found. URL: file:///C|intro.png1

 

Why is onComplet fired?

There was an error during loading.

 

Thanks

scratch

Link to comment
Share on other sites

I can see why it might appear misleading to say "loaded successfully", but as indicated in the docs a LoaderMax will continue loading its queue even if one of its child loaders fail (unless you set skipFailed to false). Otherwise, a single failure in the queue would cause the whole thing to come to a grinding halt which most developers DON'T want. They'd prefer that it keep moving and still dispatch its onComplete when it's done. If it doesn't fire its onComplete when it has finished moving through the queue, it could get in the way of the flow that the developer intends (like if he wants to load a queue and then use an onComplete to continue initializing his app). See what I mean?

 

If you prefer to have the queue stop when a failure is encountered (thus not allowing the LoaderMax to dispatch its COMPLETE event at the end of the queue), simply set skipFailed to false. Make sense?

Link to comment
Share on other sites

Hi,

 

thanks for your quick answer. I read about this parameter, but thougt it is set to false by default.

You and the docs corrected me ;)

 

skipFailed : Boolean

If skipFailed is true (the default), any failed loaders in the queue will be skipped.

 

lmaxMain.skipFailed = false;

 

Is working great!

 

Thank you

scratch

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