问题
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