Can an AS2 swf be loaded into an AS3 swf? How can I add this to the stage and interact with it from As3 swf?

两盒软妹~` 提交于 2019-12-12 18:58:08

问题


I am trying to load a swf written in AS2 into an AS3 swf - using Loader class and listening for Event.COMPLETE. in my onCompleteHandler function i want to add this to the stage so Im trying -

addChild(evt.currentTarget.content) 

... but I get the following error message:

Error #2180: It is illegal to move AVM1 content (AS1 or AS2) to a different part of the displayList when it has been loaded into AVM2 (AS3) content.

The AS2 swwf has a lot of code and I really dont want to have to migrate to AS3 if I can avoid it. Anybody know if this is possible or know of a differnt way to add the loaded swf to the stage. How do I then go about calling functions in the loaded swf?

Here is a code snippet -

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
var request:URLRequest = new URLRequest("testLoadSwf.swf");
loader.load(request);

function onCompleteHandler(evt:Event) {
   addChild(evt.currentTarget.content);
}

Thanks all.


回答1:


The only really effective way to do this is by using LocalConnection. AS2 and AS3 can't communicate much with each other. If you still have access to the AS2 file's source, you can expose some functions with LocalConnection. There's also a neat helper class by Grant Skinner called SWFBridge that takes some of the groundwork out of doing this, it's available here: http://www.gskinner.com/blog/archives/2007/07/swfbridge_easie.html




回答2:


var loader:Loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler); var request:URLRequest = new URLRequest("testLoadSwf.swf"); loader.load(request);

function onCompleteHandler(evt:Event) { //addChild(evt.currentTarget.content); } addChild(loader)



来源:https://stackoverflow.com/questions/877871/can-an-as2-swf-be-loaded-into-an-as3-swf-how-can-i-add-this-to-the-stage-and-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!