Jump to content
GreenSock

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

OnchildComplete not firing

Recommended Posts

Hi,

This time I am trying to dispose a SWF and then reloading it again with new XML works fine with below code but onChildComplete is not called.

 

 

 

function loadNewModuleAndSlide(ids) {
getNewModuleXML = getModuleXmlUrl[ids];//Setting the name for new XML file which is picked up by the SWF when it reload.
if (LoaderMax.getContent("module")) {
var getModuleAsDisplay:ContentDisplay = LoaderMax.getContent("module");
getModuleAsDisplay.dispose(true);
var myChildLoaderName:String = getParentMovie.getModuleName;

var newModuleLoader:SWFLoader;
var newModuleSwf;
newModuleLoader = new SWFLoader(myChildLoaderName,{
name:"module",
maxConnections:1,
estimatedBytes:5000,
onComplete:newModuleLoaderComplete,
onprogress:newModuleLoaderProgress,
onChildProgress:newModuleChildProgress,
onChildComplete:newModuleChildComplete
});
newModuleLoader.load();
}
//;
function newModuleLoaderProgress(event:LoaderEvent) {
ExternalInterface.call("console.log", 'MENU____Module PROGESS');
}
function newModuleLoaderComplete(event:LoaderEvent) {
//trace(event.target.progress);
ExternalInterface.call("console.log", 'MENU____Module COMPLETE');
newModuleSwf = event.target.content as ContentDisplay;
getParentMovie.addChild(newModuleSwf);
getParentMovie.setChildIndex(newModuleSwf, 0);
}
function newModuleChildProgress(event:LoaderEvent) {
ExternalInterface.call("console.log", 'MENU____Module PROGESS');
}
function newModuleChildComplete(event:LoaderEvent) {
trace("SWF Complete Loading_____________");
ExternalInterface.call("console.log", 'MENU____CHILD COMPLETE');
event.target.rawContent.nextSlides(null);

}

Link to comment
Share on other sites

Got this but it gave me bunch of error as

requireWithRoot:root.this messed up all my stage.stageWidth.

Any Idea?

Link to comment
Share on other sites

its the stage which is tracing null. So, do I have to remove all the instances of stage from that child movie. What are my options?

 

Thanks

Link to comment
Share on other sites

It sounds like your loaded swf is trying to access its stage before its added to the display list in the parent swf. Very similar to these posts, although they use an AS3 Loader and not a SWFLoader (same concepts apply):

 

http://www.kirupa.com/forum/showthread.php?321180-loading-external-swf-fails-with-stage-access

 

http://www.kirupa.com/forum/showthread.php?286508-Referencing-the-stage-from-a-loaded-swf

 

More info on ADDED_TO_STAGE

http://www.emanueleferonato.com/2009/12/03/understand-added_to_stage-event/

 

Also keep in mind that if your loaded swf targets stage, once your swf is loaded into the parent, stage now refers to the stage of the parent. All objects on the display list share the same stage.

 

http://jaycsantos.com/flash/do-you-know-actionscript-as3-stage/#.UQH3CkrHcmw

Link to comment
Share on other sites

ok the stage issue is been solved by adding addEventListener(Event.ADDED_TO_STAGE, loadModuleAssets);

 

But two questions remains unanswered 

1. Why stage get null only when I add requireWithRoot:this.root. Else works fine.

 

2. Still can't can't the progress of child SWF images to sibling.

 

below are code

 

code on sibling that telling SWF to load on parent

 

function loadNewModuleAndSlide(ids) {
	getNewModuleXML = getModuleXmlUrl[ids];
	if (LoaderMax.getContent("module")) {
		var getModuleAsDisplay:ContentDisplay = LoaderMax.getContent("module");
		getModuleAsDisplay.dispose(true);
		var myChildLoaderName:String = getParentMovie.getModuleName;

		var newModuleLoader:SWFLoader;
		var newModuleSwf;
		newModuleLoader = new SWFLoader(myChildLoaderName,{
		name:"module",
		maxConnections:1,
		requireWithRoot:this.root,
		estimatedBytes:5000,
		onComplete:newModuleLoaderComplete,
		onprogress:newModuleLoaderProgress,
		onChildProgress:newModuleChildProgress,
		onChildComplete:newModuleChildComplete
		});
		newModuleLoader.load();
	}

 

 

 

Then code inside the SWF thats being loaded on parent

 

var moduleXMLLoader:XMLLoader;
LoaderMax.activate([ImageLoader,SWFLoader]);
	
moduleXMLLoader = new XMLLoader("modules/xmls/"+ moduleXmlUrl, {
	alternateURL:"xmls/working.xml",
	name:"slides", 
	maxConnections:1, 
	estimatedBytes:5000, 
	requireWithRoot:this.root,
	onComplete:moduleXMLLoaderComplete,
	onProgress:moduleXMLLoaderProgress,
	onChildProgress:imageLoadProgress,
	onChildComplete:imageLoadComplete
	});
	XML.ignoreWhitespace = true;
	moduleXMLLoader.load();

 

Thanks

Link to comment
Share on other sites

Alright, I have to add container:getParentMovie to get the image progress.

 

Thanks

Link to comment
Share on other sites

Hi

Now I have another scenario where I can't get the progress of child images. Let me explain.

 

I have a parent SWF name course.swf that loads XML. name course.xml

Now course.xml has a SWFLoader that loads SWF name module.swf. This works fine and I can get the progress of module.swf.

 

Now here is the Issue. 

module.swf load another XML name module.xml and that xml loads bunch of images. Now I want the grand parent(course.swf) to get the progress of its child SWF and its grand child images all together.

 

Is that possible?

 

Thanks

Link to comment
Share on other sites

As I understand it, this is how your loaders are nested

toplevel swf
--XMLLoader: course.xml
----SWFLoader: module.swf
------XMLLoader: module.xml
--------ImageLoader: image1.jpg
--------ImageLoader: image2.jpg
--------ImageLoader: image3.jpg

Yes, you can nest loaders as deep as you want and have them all be part of the progress of the course.xml XMLLoader.

be sure to set requireWithRoot on the XMLLoader for module.xml. Also it would be advisable to set estimatedBytes on all the loaders.

In addition make sure all the loaders in the XMLLoaders are set to load with load="true".

Link to comment
Share on other sites

I created a very simplified set of examples.

 

course.swf loads course.xml which loads module.swf which loads module.xml which loads 4 ImageLoaders

 

course.swf

import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.display.*;
LoaderMax.activate([SWFLoader, ImageLoader]);


var courseXML:XMLLoader = new XMLLoader("course.xml", {onProgress:progressHandler, onInit:initHandler, onComplete:completeHandler, estimatedBytes:320000});
courseXML.load();


function progressHandler(e:LoaderEvent):void{
    trace("courseXMLLoader.progress = " + e.target.progress);
    bar.scaleX = e.target.progress;
    }


//fired once xml is processed and sub-loaders are created
function initHandler(e:LoaderEvent):void{
    var childSWF:ContentDisplay = LoaderMax.getContent("module.swf");
    childSWF.y = 25;
    addChild(childSWF);
    addChild(bar);
    }


function completeHandler(e:LoaderEvent):void{
    trace("courseXMLLoader *** COMPLETE ***");
    } 
 

course.xml

<data>
    <SWFLoader url="module.swf" load="true" estimatedBytes="320000"/>   
</data>
 

 

module.swf

import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;
LoaderMax.activate([ImageLoader]);


var moduleXML:XMLLoader = new XMLLoader("module.xml", {onProgress:progressHandler, onComplete:completeHandler, onChildComplete:childComplete, requireWithRoot:this.root, estimatedBytes:320000});
moduleXML.load();


function progressHandler(e:LoaderEvent):void{
    trace("moduleXMLLoader.progress = " + e.target.progress);
    }
    
function completeHandler(e:LoaderEvent):void{
    trace("moduleXMLLoader *** COMPLETE ***");
    }
    
function childComplete(e:LoaderEvent):void{
    trace(e.target);
    e.target.content.y = 25;
    addChild(e.target.content);
    }    
 

module.xml

 

<data>
    <ImageLoader url="whale.png" estimatedBytes="66000" load="true"/>
    <ImageLoader url="lobster.png" estimatedBytes="94000" load="true"/>
    <ImageLoader url="crab.png" estimatedBytes="94000" load="true"/>
    <ImageLoader url="bird.png" estimatedBytes="66000" load="true"/>
</data>
 

zip attached with cs5 source and all images, swfs, and xml

 

Open course.fla, export, and then use "simulate download"
 
You will see that courseXML XMLLoader doesn't fire its onComplete (traced) until the module.xml loads all its images and fires its onComplete. Also you will see a progress bar driven by courseXML that shows that the progress of all the swfs and images loading is integrated into its progress

nestedLoaders.zip

Link to comment
Share on other sites

Thanks Carl, your example is great but I think something is wrong in my code which is creating issue.

The difference between your example and mine is that mine course.xml is loading 4 different SWF and yours only one.

Also I am not using the onInit listener in course.fla. Below is the code. I tried to use on Init listener it but it throws error. I am sure something is wrong in course.fla and not in module.fla as it loads fines when I just have one swf in course.xml

 

 

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

var getModuleName;
var configSWFs:ContentDisplay;

LoaderMax.activate([SWFLoader]);

var configLoader:XMLLoader = new XMLLoader("assets/xmls/course.xml", {
name:"course", 
maxConnections:1, 
estimatedBytes:5000, 
onComplete:configCompleteHandler,
onProgress:ConfigProgressHandler,
onChildProgress:configSWFProgressHandler,
onChildComplete:configSWFLoadComplete
});
configLoader.load();

function ConfigProgressHandler(event:LoaderEvent):void {
    trace("progress: " + event.target.progress);
}

function configCompleteHandler(event:LoaderEvent):void { 
LoaderMax.getLoader("header").rawContent.courseTitleTxt = configLoader.content. @ courseTitle;
    LoaderMax.getLoader("header").rawContent.dispatchEvent(new Event("setCourseTitle"));
    var getModuleAsDisplay:ContentDisplay = LoaderMax.getContent("module");
    getModuleName = configLoader.content.SWFLoader[3]. @ url
    setChildIndex(getModuleAsDisplay, 1);
}
function configSWFProgressHandler(event:LoaderEvent):void {
    //trace("progress: " + event.target.progress);
}
function configSWFLoadComplete(event:LoaderEvent):void {
    configSWFs = event.target.content as ContentDisplay;
    addChild(configSWFs);
}
Link to comment
Share on other sites

The only reason I used the onInit is because I wanted the swf that loaded the 4 images to be visible prior to everything else loading.This enabled us to see each image loading and the progress being adjusted accordingly.  I don't know if you need that in your setup or why it caused an error.

 

Its hard to troubleshoot what you have provided without knowing where the errors are coming from. Am I missing something?

 

I would start by putting some traces in

 

 

 

function configSWFLoadComplete(event:LoaderEvent):void {
 trace("child = " + e.target + " " e.target.content);
    configSWFs = event.target.content as ContentDisplay;
    addChild(configSWFs);
}
 

are all the children SWFLoaders? or do you have a LoaderMax in there?

Link to comment
Share on other sites

This is how my xml look like

 

<?xml version="1.0" encoding="iso-8859-1"?> 
<config name='course'>
	
	<SWFLoader name="menu" url="skin/menu.swf" estimatedBytes="49307" load="true"  x="0" y="0" />
	<SWFLoader name="control" url="skin/controller.swf" estimatedBytes="78596" load="true"  x="0" y="0" />
	<SWFLoader name="help" url="skin/help.swf" estimatedBytes="49307" load="true"  x="0" y="0" />
	<SWFLoader name="header" url="skin/header.swf" estimatedBytes="33855" load="true"  x="0" y="0" />
	<SWFLoader name="module" url="modules/module.swf" estimatedBytes="77928" load="true"  x="0" y="0" />
	
</config>
Link to comment
Share on other sites

Hi Carl, I have attached the zip. Its based on the same zip that you sent but I tried to add the same scenario that I have in my project. But before getting the the complete progress of all child in one preloader I am hit by error. Looks like the its trying to convert xml in comtent display.

When I trace e.target.content it also getting me raw XML thats why getting error. 

FYI, I am not gettind the same error in my my project. Below is the test result of

 

function configSWFLoadComplete(event:LoaderEvent):void {
 trace("child = " + e.target + " " e.target.content);
    configSWFs = event.target.content as ContentDisplay;
    addChild(configSWFs);
}

 

Trace Result

child = SWFLoader 'menu' (skin/menu.swf)__[object ContentDisplay]
child = SWFLoader 'control' (skin/controller.swf)__[object ContentDisplay]
child = SWFLoader 'help' (skin/help.swf)__[object ContentDisplay]
child = SWFLoader 'header' (skin/header.swf)__[object ContentDisplay]
child = SWFLoader 'module' (modules/module.swf)__[object ContentDisplay]
**********assets Loaded*********

Here is the link to download the zip

 

http://alnoor.us/nestedLoaders.zip

 

Can you please look in it

 

Thanks

Link to comment
Share on other sites

Thanks for providing the files. Very helpful.

 

Yes the problem is that the courseXML XMLLoader has many children of many different types. Remember courseXML is tracking the progress of module.swf, module.xml, moduel2.xml and module2.swf and all the images that each module loads. Your courseXML onChildComplete handler is trying to use the content of all those assets as ContentDisplay objects. When module.xml and module2.xml load, that's where the errors happen.

 

Change the code in course.fla to

 

 

 

function onChildComp(e:LoaderEvent):void{


//PAY ATTENTION TO THIS TRACE//


    trace("*** COURSE XML CHILD IS = " + e.target)


    if(e.target is XMLLoader){
        trace("ignore xml");
    }else{
        childSWFs = e.target.content as ContentDisplay;
        childSWFs.y = 25;
        addChild(childSWFs);
        addChild(bar);
    }
}
 

gives the following traces:

 

 

*** COURSE XML CHILD IS = ImageLoader 'loader9' (lobster.png)
*** COURSE XML CHILD IS = ImageLoader 'loader8' (whale.png)
*** COURSE XML CHILD IS = ImageLoader 'loader7' (test.jpg)
*** COURSE XML CHILD IS = XMLLoader 'loader3' (module2.xml)
ignore xml
*** COURSE XML CHILD IS = SWFLoader 'loader2' (module2.swf)
*** COURSE XML CHILD IS = ImageLoader 'loader11' (bird.png)
*** COURSE XML CHILD IS = ImageLoader 'loader10' (crab.png)
*** COURSE XML CHILD IS = XMLLoader 'loader5' (module.xml)
ignore xml
*** COURSE XML CHILD IS = SWFLoader 'loader1' (module.swf)
 
You will see all the objects that are considered children of courseXML. I put a little conditional statement in there so that if a child loader is an XMLLoader, it will be ignored and not have its content cast as a ContentDisplay object. So in essence everything you load via course.xml will be parsed through this function. 
 
Does this help?
Link to comment
Share on other sites

Yes, it helped to clear the error and complete event is fired after all the children and images are loaded  BUT

Now the percentage of the module2.swf starts in between from 30%

Like, the startup is fine all the four images load fine till 50 % and then its tile for module2,swf to load images it drops to 30% below is the trace report. Looks like something is happening when its ignoring the XML

 

courseXMLLoader.progress = 0
courseXMLLoader.progress = 3
courseXMLLoader.progress = 3
courseXMLLoader.progress = 21
courseXMLLoader.progress = 26
*** COURSE XML CHILD IS = ImageLoader 'loader6' (lobster.png)
*** COURSE XML CHILD IS = ImageLoader 'loader5' (whale.png)
courseXMLLoader.progress = 35
*** COURSE XML CHILD IS = ImageLoader 'loader8' (bird.png)
*** COURSE XML CHILD IS = ImageLoader 'loader7' (crab.png)
*** COURSE XML CHILD IS = XMLLoader 'loader3' (module.xml)
ignore xml
courseXMLLoader.progress = 48
*** COURSE XML CHILD IS = SWFLoader 'loader1' (module.swf)
courseXMLLoader.progress = 51
courseXMLLoader.progress = 50
courseXMLLoader.progress = 37
courseXMLLoader.progress = 42
courseXMLLoader.progress = 48
courseXMLLoader.progress = 54
courseXMLLoader.progress = 60
courseXMLLoader.progress = 66
courseXMLLoader.progress = 72
courseXMLLoader.progress = 77
courseXMLLoader.progress = 83
courseXMLLoader.progress = 89
courseXMLLoader.progress = 95
*** COURSE XML CHILD IS = ImageLoader 'loader11' (test.jpg)
*** COURSE XML CHILD IS = XMLLoader 'loader9' (module2.xml)
ignore xml
*** COURSE XML CHILD IS = SWFLoader 'loader2' (module2.swf)
courseXMLLoader.progress = 100
courseXMLLoader *** COMPLETE ***
Link to comment
Share on other sites

I think that drop progress % is just a discrepancy between your estimatedBytes and the actual bytes.

for instance module2.xml has

 

estimatedBytes="66000" but the test.jpg image that it loads is 776924 bytes

 

.

Also I don't think that you are accounting for this test.jpg image's size in the parent courseXMLLoader. So what is happening is that LoaderMax bases the progress on the estimatedBytes you provide and then when it encounters a much larger file it adjusts on the fly. Once module2.xml loads LoaderMax basically says "oh shucks, I'm not nearly as done as I thought as was" and then modifies the progress to be as accurate as possible based on this new information.

Link to comment
Share on other sites

So, suppose if module2.xml has 20 images then I have to add all the estimated sizes of 20 images in the module2.fla and also in course.fla to get the smooth preloading %

Link to comment
Share on other sites

Tried all variation estimated bytes in swf and xml but can't get to work. I added link to the zip in which I added exact extimatedBytes in swf as well as in XML for each files. Not sure where I wrong.

 

http://alnoor.us/module2.zip

 

 

Thanks

Link to comment
Share on other sites

Yes, in order to get the most accurate loading progress you have to do a bit of work to tell the top level XMLLoader how much data it is going to expect. 

 

So courseXML:XMLLoader needs an estimatedBytes closer to 1127000 to account for ALL the child and grandchild assets it is going to load.

 

When assigning estimatedBytes for any XMLLoader you have to account for the size of the xml file, the size of the file it is loading and the size of the assets that file is loading.

 

 

so course.xml might look something like this:

 

 

<data>
    <SWFLoader url="module2.swf" load="true" estimatedBytes="350000"/> 
    <SWFLoader url="module.swf" load="true" estimatedBytes="777000"/>
</data>

 

 

in module.fla and module2.fla your xmlLoaders need estimated bytes like this:
 
module2.fla

 

var moduleXML:XMLLoader = new XMLLoader("module2.xml", {onProgress:progressHandler, cononComplete:completeHandler, onChildComplete:childComplete, requireWithRoot:this.root, estimatedBytes:777000});
 

 

 
module.fla

 

var moduleXML:XMLLoader = new XMLLoader("module.xml", {onProgress:progressHandler, onComplete:completeHandler, onChildComplete:childComplete, requireWithRoot:this.root, estimatedBytes:350000});
 

the bytes I'm using are rough estimates, but are close enough that LoaderMax doesn't get any big surprises while it finds out that it has more and more assets to load. 

 

The reason you were seeing jumping in your files is that you weren't using bytes. You had numbers like 339 instead 339000.

Link to comment
Share on other sites

Thanks Carl, this explains a lot and I got my test flas working great with your wonderful instructions. But the issue in my project is still not solves as its calling the child complete event later then parent complete event. After playing around for couple hours I found that I have added the below code because I was getting stage undefined.

 

addEventListener(Event.ADDED_TO_STAGE, addedToStage);
 

So here's the overall scenario

To make preloader work I have to add requireWithRoot:this.rootbut then I loose the stage. 

To get back the stage I added ADDED_TO_STAGE. then I loose the preloader.

 

So its cycle. Looking for more options.

Thanks

Link to comment
Share on other sites

I don't know if I'm following the last part.

 

 

 

I think if you are waiting for a child swfs ADDED_TO_STAGE to fire PRIOR to constructing a subloaded swf's additional loaders you could have this problem.

 

What is most likely happening is the parent loader is waiting for the child swf to load. The parent loader sees that it has loaded all the bytes of the swf and says "ok I'm now complete" and then an instant later the child swf gets added to the stage and says "hey wait buddy! I got a bunch more stuff for you!"

 

Can you modify the simplified example files we have been sharing so that I can see the problem?

Is there a logical way to separate code that needs the stage from your XMLoader/SWFLoader code? The most important aspect of this setup is that the requireWithRoot code must be executed as soon as possible in order for the parent loaders to maintain accurate progress tracking. 

Link to comment
Share on other sites

Here's some progress.

In process of simplifying my project to get to the core of the issue. I removed all the stage reference from my child FLA. Now pre-loader works fine but my very first old issue still stays there and that is when I add requireWithRoot:this.root then the position of all the images are lost.

 

Now heres what I found.

I am adding each image in its own container call imageHolder. Then I am setting the x and y position of the imageHolder. Now when I preview child by its then all is happy. Child loaded in its own holder and holder are place right on its place. below is the sample code

var imageHolder:Sprite;
var img:ContentDisplay;
var num = 0
function onchildComplete(e:Event){

 imageHolder = new Sprite();
 img = e.target.content as ContentDisplay;
 imageHolder.addChild(img);
 imageHolder.x = 100*num
 num++


}

now as soon as I add requireWithRoot:this.root. then image lost all its position when child swf loaded in parent swf but place right when its playing by it self.

 

Here is the important thing I noticed that requireWithRoot:this.root added then image doesn't load in its holder and that is why even though imageHolder are posed right image fall out of its position. 

 

Still digging in....

Link to comment
Share on other sites

Alright, attached the simplified files.

 

Notice that when you play the module by itself all works well but as you load in parent swf then images are not resize and get stage null. Take of the requiredRoot then child works fine in parent as well but preloader breaks.

 

So issues.

Image break out of holder when using requiredRoot.

Not using required root breaks the preloader.

Stage is always null in parent swf till you set event listener ADDED_TO_STAGE.(that flash issue)

but adding ADDED_TO_STAGE breaks the preloader.

 

There are also possibility that I am calling ADDED_TO_STAGE at wrong time. Actually I am calling it on very top when (parent is loader) true and then when added to stage load the XML loader 

 

hope explain well.

 

 

Thank you.

module.zip

Link to comment
Share on other sites

ok, I see what is happening.

 

Add this to the bottom of the code in module.fla

 

 

 

this.addEventListener(Event.ADDED_TO_STAGE, onStage);


function onStage(e:Event):void{
    trace("\n + **** \n MODULE ON STAGE **** \n")
    }
 

 

That will let us know exactly when module.fla is added to course.xml's stage

 

export module.swf

export course.swf

 

These are some of the last few traces

 

 

*** COURSE XML CHILD IS = ImageLoader 'loader11' (bird.png)
null_-_stage on child
[object Stage]__stage on parent
*** COURSE XML CHILD IS = ImageLoader 'loader10' (crab.png)
[object Stage]__stage on parent
*** COURSE XML CHILD IS = XMLLoader 'loader6' (module.xml)
ignore xml
[object Stage]__stage on parent
*** COURSE XML CHILD IS = SWFLoader 'loader2' (module.swf)
 
 + **** 
 MODULE ON STAGE **** 
 
courseXMLLoader.progress = 100
courseXMLLoader *** COMPLETE ***
 
A few things that this shows
 
1: module.swf is the last child of courseXML to load before courseXMLLoader is complete
2: module.swf is the last item to be placed on the stage
 
Since module.swf has requireWithRoot set and it has an XMLLoader with require with root set that means that module.swf and all of its sub-assets must be loaded before its own COMPLETE event fires. It won't be added to the stage until everything loads.
 
Now towards the top of those traces you see when the various images that module.swf is loading have loaded
 
*** COURSE XML CHILD IS = ImageLoader 'loader11' (bird.png)
null_-_stage on child
[object Stage]__stage on parent
*** COURSE XML CHILD IS = ImageLoader 'loader10' (crab.png)
 
Remember those are all children of the courseXML XMLLoader.
In course.fla you are trying to add the content of those loaders to the stage with:
 

 

  childSWFs = e.target.content as ContentDisplay;
       // childSWFs.y = childSWFs.y+25;
        addChild(childSWFs);
 

 

The problem is, inside module.fla you are also trying to add those images to an imageHolder and then place that imageHolder on the stage

 

 

 

function childComplete(e:LoaderEvent):void{
    trace(stage+'_-_stage on child');
    imgHolder = new Sprite();
    addChild(imgHolder);
    //e.target.content.y = 25;
    imgHolder.addChild(e.target.content);
    imgHolder.width = 100;
    imgHolder.height = 100;
    imgHolder.y = 25;
    imgHolder.x = 100*num
    num++


    }  
 

So basically you are using addChild in multiple places to add the same asset to multiple objects.

 

Keep in mind the images you load are already in ContentDisplay objects, which are in essence fancy sprites. You don't need to add the content of your ImageLoaders to new Sprites. You can place the content where every you like and also set things scaleMode, fitWidth and fitHeight:

http://api.greensock.com/as/com/greensock/loading/display/ContentDisplay.html

 

So basically you don't need a new imgHolder to set the x, y, width and height. You can do that all to the contentDisplay object (if you like).

 

to fix the main issues with null stage and mis-sized images:

 

In course.xml don't attempt to add all the children  of the courseXML loader (which includes all the swfs and all the images) to the stage onChildComplete of courseXML. 

 

Once courseXML loads its XML use an onInit (which runs as soon as the xml is loaded and the appropriate SWFLoader objects are loaded ) and parse the xml to find out which SWFLoaders the xml contains. Immediately add the content of those SWFLoaders to the stage of courseXML.

 

Unfortunately I can't do that right now. But as a quick test just replace all your code in course.fla with this

 

 

 

 

import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.display.*;
LoaderMax.activate([SWFLoader, ImageLoader]);
var childSWFs:ContentDisplay
var courseXML:XMLLoader = new XMLLoader("course.xml", {onInit: onInit, onProgress:progressHandler,maxConnections:1,  onComplete:completeHandler, estimatedBytes:1127000 });
courseXML.load();


function progressHandler(e:LoaderEvent):void{
    trace("courseXMLLoader.progress = " + Math.round(e.target.progress*100));
    bar.scaleX = e.target.progress;
    }


//fired once xml is processed and sub-loaders are created
function onInit(e:LoaderEvent):void{
    //note module2.swf will be behind module.swf
    addChild(LoaderMax.getContent("module2.swf"));
    addChild(LoaderMax.getContent("module.swf"));
    addChild(bar);
    }
    

function completeHandler(e:LoaderEvent):void{
    trace("courseXMLLoader *** COMPLETE ***");
    //trace(e.target.content)
    }    
 

You won't get any null stages and module.swf will display with all the images sized and placed the way you want.

 
Oh, and if you are feeling frustrated, don't fret. This is probably the most ambitious LoaderMax setup I have seen posted in the forums. LoaderMax was built for this. There's just a lot you need to know to get it all peachy.
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.
×