Jump to content
Search Community

Remove failed child loaders from XMLLoader?

Mr Pablo test
Moderator Tag

Recommended Posts

How can I go about removing failed loaders from my XML Loader?

 

E.g. I have an xml doc defining a SWF, then 2 videos.

 

If, for example, the SWF fails to load for what ever reason, how can I remove it from the XML Loader list?

 

Currently, if an asset fails to load e.g. incorrect path, the XML Loader still tries to load the asset into the container.

 

I know there is an "onChildFail" event, but I cannot see anything about removing the failed child loader from the main loader?

Link to comment
Share on other sites

I'm a little confused about something you said - what do you mean by "if an asset fails to load, the XMLLoader still tries to load the asset into the container"? As far as I know, if something fails to load, it simply fails to load and the LoaderMax queue moves on. Did you mean that the ContentDisplay object that was created with the loader still exists (with no rawContent inside)? 

 

Normally you really shouldn't have to worry about doing cleanup on a failed loader. It just fails. 

 

You can dispose() the offending loader if you want - that removes it from any queues that it was in. 

Link to comment
Share on other sites

I'm guessing it's my implementation that is to blame, due to not knowing the ins and outs of LoaderMax :)

 

Currently, I have a working XML Loader that reads my XML doc (which contains 3 assets, 1 SWf and 2 videos)

 

After the XML Loader has completed loading the assets, my completeHandler runs a function to display the first asset in the list.

 

Here is the function:

 

public function showAsset(index:int):void
			{

				dynamicLoad = LoaderMax.getLoader("dynamicLoaderMax");
				currentAsset = dynamicLoad.getChildAt(index);
				
				trace(dynamicLoad.getChildren().length);
				
				//var currentAsset = xmlLoad.getContent("dynamicLoaderMax");
				
				trace("currentAsset = " + currentAsset);
				
				//detect what type of asset needs to be shown and played
				if(currentAsset is ImageLoader){
					trace("ImageLoader detected");
				}
				
				if(currentAsset is VideoLoader){
					trace("VideoLoader detected");
					currentAsset.gotoVideoTime(0, true);
					currentAsset.addEventListener(VideoLoader.VIDEO_COMPLETE, onVideoComplete);
				}	
				
				if(currentAsset is SWFLoader){
					trace("SWFLoader detected");
					currentAsset.content.visible = true;
					currentAsset.rawContent.gotoAndPlay(2);
					addEventListener(Event.ENTER_FRAME, trackSWFPlayback);
				}
				
				addElement(currentAsset.content);
			}

 

As you can see, I am using the XML document itself as a reference to the assets (this is so I can play them in a loop - see my previous posts)

 

So the issue is arising because if asset 1 fails to load in the XML Loader, and I am trying to play it with my function shown above, I get problems.

 

How can else can I get a reference to the assets in order to play the first one (that has loaded successfully) and loop them?

Link to comment
Share on other sites

There are several ways:

  1. Add an onChildComplete listener to the XMLLoader. In that handler, add each loader to an array as it completes so that by the time XMLLoader finishes, you've got a nice, tidy array of successfully loaded LoaderItems. 

     

    function childCompleteHandler(event:LoaderEvent):void {
        loaders.push(event.target);
    }
    
  2. You could get the XMLLoader's internal LoaderMax (using the XMLLoader's name plus "_ParsedLoaders", meaning you can do LoaderMax.getLoader( yourXMLLoader.name + "_ParsedLoaders")) and use its getChildrenByStatus() method like queue.getChildrenByStatus(LoaderStatus.COMPLETED). That'll return an array for you. 
Link to comment
Share on other sites

I'm trying to implement option 2 as you described, but I cannot seem to get anywhere.

 

I have my XML doc, and I've made it so only 1 out of a few assets will actually load (basically, I deleted the other asset files in the folder)

 

Here is my code to try and get some kind of output in the console:

 

Handler for when the XMLLoader completes:

 

 

 

public function completeHandler(e:LoaderEvent):void
            {
                traceChildren( LoaderMax.getLoader(xmlLoad.name + "_ParsedLoaders") );
            }
 

"xmlLoad" is the XMLLoader

 

traceChildren function (to hopefully output some info to console to show the one asset is complete and OK to use:

 

 

 

function traceChildren(queue:LoaderMax):void {
                var test:Array = queue.getChildrenByStatus(LoaderStatus.COMPLETED);
                
                trace(test);
            }

 

Console output:

 

 

 

LoaderMax 'dynamicLoaderMax'
 

"dynamicLoader" is the name of the loadermax node in my XML doc.

 

Shouldn't I be seeing an array with the one complete asset in it?

 

Or is that LoaderMax reference a new loader that I can reference directly? How would I reference it to make sure I only tried to access complete assets?

Link to comment
Share on other sites

You forgot to set the "includeNested" parameter to true.

 

And to be clear, the XMLLoader created an internal LoaderMax, named xmlLoad.name + "_ParsedLoaders" in your case. That will contain the parsed loaders, of course, and it will leave the hierarchy in place. So if in your XML, you've got your loader nested inside of a <LoaderMax> node, then that <LoaderMax> is the child of the _ParsedLoaders one. So let's say your xmlLoad.name is "myLoader", and the <LoaderMax node in your XML is named "xmlLoaderMax", it'd be like:

 

myLoader_ParsedLoaders > xmlLoaderMax > yourNestedLoader

 

So when you did the getChildrenByStatus() call, it only looked at the direct children of the myLoader_ParsedLoaders. If you want it to also search deeper nested descendants, use the 2nd parameter:

 

var test:Array = queue.getChildrenByStatus(LoaderStatus.COMPLETED, true);

The getChildren() method also has an "omitLoaderMaxes" parameter to further refine things, but that's wasn't present in getChildrenByStatus() method, but I'll add that to the release that's getting posted later this evening.  

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