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++){
tra开发者_JS百科ce(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
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
精彩评论