views:

13

answers:

1

Hi, i'm developing an app that use swf to load elements and add properties to the loaded swf. I use SWFLoader to load the movie and on the COMPLETE event i move the loaded MovieClip to a specific frame and then list its DisplayList. I've discovered that if i traverse the list soon it's note loaded. Maybe it's cleaner with code:

loader.addEventListener(Event.COMPLETE, function(evt:Event):void{
    var mc:MovieClip = MovieClip(loader.content);
    mc.gotoAndStop(frameNumber);
    for(i = 0; i < mc.numChildren; i++){
         trace(mc.getChildAt(i));
    }
}

I miss some children from the loaded swf and in some cases i get null values. Now i've added a Timer() that wait 250ms before listing the display list and works but it's very slow and inefficient.

The other strange behaviour is that with the previous snippet i can't get some MovieClip, even with the Timer in place. I had to insert a function in the loaded swf like this:

function getItems():Array{
    var res:Array = [];
    for(var i:uint = 0; i < this.numChildren; i++){
        res.push(this.getChildAt(i));
    }
    return res;
}

To retrieve the correct list of children.

Thanks a lot

A: 

Are you using the Loader class, if so, you need to add the event listener to the loader's contentLoaderInfo property, not the loader object itself. It is a very common mistake.

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(evt:Event):void{
    var mc:MovieClip = MovieClip(loader.content);
    mc.gotoAndStop(frameNumber);
    for(i = 0; i < mc.numChildren; i++){
         trace(mc.getChildAt(i));
    }
}

HTH

George Profenza
Hi, i'm using Flex SWFLoader (a Flex subclass of the Laoder class) and wait for that event. The problem is that when the movie is loaded i call mc.gotoAndStop() and then list mc children to quickly when the children in the new frame are still null.
wezzy
Ok, now I know which SWFLoader, can you try using the INIT handler instead ?
George Profenza