可以将AS2 swf加载到AS3 swf中吗?如何将其添加到舞台并与As3 swf进行交互?

时间:2022-11-11 23:44:29

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 -

我正在尝试将AS2中编写的swf加载到AS3 swf中 - 使用Loader类并侦听Event.COMPLETE。在我的onCompleteHandler函数中,我想将它添加到舞台上,所以我在尝试 -

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?

AS2 swwf有很多代码,如果可以避免的话,我真的不想迁移到AS3。任何人都知道这是否可行,或者知道将加载的swf添加到舞台的不同方法。然后我如何在加载的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.

2 个解决方案

#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

唯一真正有效的方法是使用LocalConnection。 AS2和AS3无法相互通信。如果仍然可以访问AS2文件的源,则可以使用LocalConnection公开某些函数。还有一个由格兰特斯金纳称为SWFBridge的简洁助手课程,它完成了一些基础工作,可以在这里找到: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);

var loader:Loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onCompleteHandler); var request:URLRequest = new URLRequest(“testLoadSwf.swf”); Loader.load方法(请求);

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

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

#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

唯一真正有效的方法是使用LocalConnection。 AS2和AS3无法相互通信。如果仍然可以访问AS2文件的源,则可以使用LocalConnection公开某些函数。还有一个由格兰特斯金纳称为SWFBridge的简洁助手课程,它完成了一些基础工作,可以在这里找到: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);

var loader:Loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onCompleteHandler); var request:URLRequest = new URLRequest(“testLoadSwf.swf”); Loader.load方法(请求);

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

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