communication between as2 and as3

孤人 提交于 2019-12-13 15:22:32

问题


I have this code under a button in 'as2.swf'

on (release) {
unloadMovie(this);  
}

and this swf is being loaded into as3 container called 'main.swf', but when i press it nothing happens and the file does not unload itself. any one can enlighten me on that?


回答1:


ActionScript 3 uses the AVM2 virtual machine while ActionScript 2 uses the older AVM. This means that they are not in the same sandbox. Thus communication between the two is difficult at best.

AVM2(as3) can load and work with AVM1(as2) but AVM1 cant load AVM2.

Here is an example of how to communicate between the two:

AS3 Example:

import flash.net.LocalConnection;
import flash.display.Stage;

var receiverLC:LocalConnection = new LocalConnection()

receiverLC.connect("__myConnection");

receiverLC.client = this;  

var request:URLRequest = new URLRequest("as2Movie.swf");

var loader:Loader = new Loader();

loader.load(request);

mainLoader_mc.addChild(loader);
. 
function changeSpeed(speed:Number):void {

stage.frameRate=speed

}

AS2 Example:

var sending_lc:LocalConnection=new  LocalConnection()

function changeSpeed(num:Number){

sending_lc.send("__myConnection", "changeSpeed",num);

}

The key is that the AS2 must pass commands back to AS3 - the key is this line:

sending_lc.send("__myConnection", "changeSpeed",num);

So instead of relying on AS2 actions, send your actions to the AS3 container.

Example from: http://flashgosu.com/?tag=as2-to-as3-avm1-to-avm2



来源:https://stackoverflow.com/questions/2455649/communication-between-as2-and-as3

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