在添加到舞台之前,将子项添加到动态添加的swf中

时间:2011-06-06 10:19:12

标签: flash actionscript-3

正如标题所述,我尝试使用AS3将子项添加到动态添加的swf文件中,然后再添加到舞台上,这可能吗?

这是我到目前为止的代码,

AS3:

var mLoader:Loader = new Loader();
var mRequest:URLRequest = new URLRequest(glo.bal.base_url+"videos/vid_1.swf");
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler_one);
mLoader.load(mRequest);

function onCompleteHandler_one(loadEvent:Event)
{
    //Here I would like to add a child to the swf file before I append it to stage
    video_container.addChild(loadEvent.currentTarget.content);
}

vid_1 swf内部有一个名为box_one的影片剪辑,我想将图像附加到box_one,并且只在图像文件包含后将swf添加到舞台上已添加到box_one

任何帮助都会非常感谢大家,而不是提前!

1 个答案:

答案 0 :(得分:1)

var mLoader:Loader = new Loader();
var mRequest:URLRequest = new URLRequest(glo.bal.base_url+"videos/vid_1.swf");
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler_one);
mLoader.load(mRequest);

function onCompleteHandler_one(loadEvent:Event)
{
    var loadedClip:MovieClip = loadEvent.currentTarget.content as MovieClip;
    loadedClip.addChild(some_other_clip);
    loadedClip.someExistingChild.addChild(some_other_clip_2); // Only do this obviously if you're sure of the specifically named child of your load clip existing and in the right scope

    //This is specifically how you'd do this in your code
    loadedClip.box_one.addChild(somethingElse);
    stage.addChild(loadedClip);
}

为了安全起见,您可能希望将其包装在一些错误检查代码中:

if(loadedClip && loadedClip.box_one){
    loadedClip.box_one.addChild(somethingElse);
}

所以是的,这是可能的。