打电话到AS2功能从AS3容器容器、功能

2023-09-08 15:18:11 作者:花莞杳萝烟

我试图调用从 AS3容器这应该调用老函数 AS2 SWF 即不能编辑bacause我们正在谈论1000 SWF文件中,确实存在一些方法来调用 AS2 SWF里面的函数 AS3容器

I'm trying to call a function from a AS3 container which should call old AS2 SWF that cannot be edited bacause we are talking about 1000 swf files, does exist some way to call a function inside the AS2 SWF from the AS3 container?

我知道,通过增加一个的LocalConnection 的此处编写的,但正如我所说,我不能编辑所有的SWF文件,所以我只是想知道,如果确实存在一些替代。

I know a possible way by adding a LocalConnection as written here but as I said I can't edit all the swf files, so I just wonder to know if does exist some alternative.

推荐答案

如果你的容器绝对必须写在AS3,那​​么你可以创建另一个中介容器AS2可与1000现有的直接主权财富基金进行通信,并且可以然后与使用LocalConnection技术进行通信。

If your container absolutely has to be written in AS3, then you could create another intermediary container in AS2 that can communicate with the 1000 existing SWFs directly, and you can then communicate with that using the LocalConnection technique.

在code以下是一个简单的例子,但由于一个问题,向MovieClipLoader似乎要被加载到AS3 AVM1对象我不得不实施一个比较难看的投票系统不会触发事件。有关此问题的问题,可以发现在这里:Why当加载到AS3包装都的MovieClipLoader事件不火?。

The code below is a simple example of this, but due to an issue with the MovieClipLoader seeming to not fire events when loaded into an AS3 AVM1 object I have had to implement a rather ugly polling system. The question relating to this issue can be found be here: Why do MovieClipLoader events not fire when loaded into an AS3 wrapper?.

child_as2.swf - 其中一个是我们要加载的一千AS2文件。它定义了我们想要加载时访问它的根功能:

child_as2.swf - One of a thousand AS2 files that we are trying to load. It has defined functions on it's root that we want to access when it is loaded:

stop();

function playMovie() {
    play();
}

parent_as2.swf - 包含的LocalConnection code中的AVM1和AVM2运行时之间的桥梁中介AS2文件。由于上述的事件问题指出,这一调查child_as2.swf同时检测,当它被加载时根的已知功能可用。重要的是,在第一轮询呼叫到checkProgress被忽略,因为这将返回不正确的进展值作为这里应该注意: http://help.adobe.com/en_US/AS2LCR/Flash_10.0/00001380.html

parent_as2.swf - The intermediary AS2 file that contains LocalConnection code to bridge between the AVM1 and AVM2 runtimes. Due to the events issue noted above, this polls child_as2.swf to detect both when it is loaded and when a known function on the root is available. It is important that the first polling call to checkProgress is disregarded as this will return incorrect progress values as noted here: http://help.adobe.com/en_US/AS2LCR/Flash_10.0/00001380.html

var container:MovieClip = createEmptyMovieClip("container", 10);
var mcLoader:MovieClipLoader = new MovieClipLoader();
var loadStarted:Boolean;
var checkingInt:Number;

function checkProgress() {
    var progObj:Object = mcLoader.getProgress(container);
    if(progObj.bytesLoaded == progObj.bytesTotal && loadStarted) {
        //load complete, wait for loadInit
        if(typeof(container.playMovie) == "function") {
            //loadInit
            clearInterval(checkingInt);
            container.playMovie();
        }
    }
    //ensures the first loop is ignored due to inaccuracy with reporting
    loadStarted = true;
}

//LocalConnection code
var myLC:LocalConnection = new LocalConnection();

myLC.loadChild = function() {
    loadStarted = false;
    mcLoader.loadClip("child_as2.swf", container);
    checkingInt = setInterval(checkProgress,5);
}

myLC.connect("AVM");

parent_as3.swf - 外AS3包装。此载荷parent_as2.swf成AVM1对象,并经由的LocalConnection与它连通。

parent_as3.swf - The outer AS3 wrapper. This loads parent_as2.swf into an AVM1 object, and communicates with it via LocalConnection.

var myLC:LocalConnection = new LocalConnection();

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.INIT,onLoaded);
loader.load(new URLRequest("parent_as2.swf"));
addChild(loader);


function onLoaded(event:Event):void {
    //setTimeout hack to circumvent #2000 Security context error
    setTimeout(function() {
        myLC.send("AVM", "loadChild");
    },1);
}