开发者

How to control main timeline from external swf

I have a main.swf and inside it is just a plain container movieclip. Using the Loader function I load an external swf called content.swf inside that container. Container.swf has a button inside it. Now when external swf is loaded in container mc which is on the main.swf stage, I want to move to another frame by clicking the button of the loaded external swf. If I try to control it from the main timeline I get error saying

cannot convert flash.display::Loader@117e7041 to flash.display.M开发者_如何学JAVAovieClip.

If I try to control it from the external swf I can trace the click on the button but timeline doesn't move to the wanted frame.


From the error message it seems that you are trying to cast a loader into a movie clip. Use the loader.content property instead.

var mc:MovieClip = loader.content as MovieClip;
//do whatever you want with mc


Make sure you're using event handlers as shown here because in your case loader.content has not loaded 'content.swf' yet when you try to add it to your container.

Also it is preferable to cast like this:

var mc:MovieClip = MovieClip(loader.content);

For the simple reason that 'as' won't throw you an error is the object you're trying to cast is null or can't be casted.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜