I have 2 child swfs being loaded into a parent swf. Each child swf loads its own XML file. When I load the child swfs, I get back a null because they have not loaded their XML files yet. I am using greensock's LoaderMax. Is there anyway for the parent to know when all the child XMLs have been loaded.
Asked
Active
Viewed 259 times
1 Answers
0
It sounds like you don't want to count the children when they load, but rather when the children are done loading some XML. Consider first making a class for each/all of your children that will be loading xml, something like:
package {
import flash.display.MovieClip;
public class ChildToLoad extends MovieClip{
public function ChildToLoad() {
// Load xml here, optionally use URLLoader or XMLLoader,
// but regardless of what you use, listen for when XML load
// is complete and handle it with the loadComplete() function
...
someXMLLoader.addEventListener(Event.COMPLETE, loadComplete);
...
}
private function loadComplete(evt:* = null)
{
var padre:MovieClip = parent as MovieClip;
padre.childLoaded(); // Call function of parent
}
}
}
Then in your main swf (your parent) do something like:
var child1:ChildToLoad = new ChildToLoad();
var child2:ChildToLoad = new ChildToLoad();
addChild(child1);
addChild(child2);
var loadedChildrenCount:int = 0;
function childLoaded() // Called by all children after they load XML
{
trace("childLoaded()");
loadedChildrenCount++;
if(loadedChildrenCount == 2)
{
trace("All children have loaded! Do Stuff!");
}
}
However; If I read too much into your question ...
LoaderMax has a onChildComplete
handler you can use
A handler function for LoaderEvent.CHILD_COMPLETE events which are dispatched each time one of the loader's children (or any descendant) finishes loading successfully. Make sure your onChildComplete function accepts a single parameter of type LoaderEvent (com.greensock.events.LoaderEvent).
You can try something like:
var childrenLoadedCount:int = 0;
var queue:LoaderMax = new LoaderMax({
onChildComplete:AChildWasLoaded,
TODO:AddYourOtherArgumentsHere
});
...
function AChildWasLoaded(evt:LoaderEvent)
{
childrenLoadedCount++;
if(childrenLoadedCount = 2)
{
// All children have loaded
}
}

ToddBFisher
- 11,370
- 8
- 38
- 54