无法使SWF与AIR通信工作

时间:2016-10-13 01:40:34

标签: actionscript-3 air localconnection

我尝试在浏览器中运行SWF并让它与捆绑为Windows的exe的AIR应用程序进行通信。

在我的AIR应用程序(接收器)中,我有以下

package
{
import flash.display.Sprite;
import flash.events.StatusEvent;
import flash.net.LocalConnection;
import flash.text.TextField;

/**
 * ...
 * @author
 */
public class Main extends Sprite
{
    private var _tf:TextField;

    public function Main()
    {
        var localConnection:LocalConnection = new LocalConnection();
        localConnection.addEventListener(StatusEvent.STATUS, handleConnectionStatus);
        localConnection.allowDomain("*");
        localConnection.client = this;
        localConnection.connect("_myConnection");

        _tf = new TextField();
        _tf.appendText("Creating local connection\n" + localConnection.domain + "\n");
        _tf.width = stage.stageWidth;
        _tf.height = stage.stageHeight;
        addChild(_tf);
    }

    private function handleConnectionStatus(e:StatusEvent):void
    {
        _tf.appendText("handleConnectionStatus\n");
        _tf.appendText(e.code + "\n");
        _tf.appendText(e.level + "\n");

    }

    public function testMethod():void
    {
        _tf.appendText("You wrote \n");
    }
}
}

在发件人中,我在网上的SWF

package
{
import flash.display.Sprite;
import flash.events.AsyncErrorEvent;
import flash.events.Event;
import flash.events.SecurityErrorEvent;
import flash.events.StatusEvent;
import flash.net.LocalConnection;
import flash.text.TextField;

/**
 * ...
 * @author
 */
public class Main extends Sprite
{
    private var _tf:TextField;

    public function Main()
    {
        if (stage) init();
        else addEventListener(Event.ADDED_TO_STAGE, init);
    }

    private function init(e:Event = null):void
    {
        removeEventListener(Event.ADDED_TO_STAGE, init);
        // entry point

        _tf = new TextField();
        _tf.width = stage.stageWidth;
        _tf.height = stage.stageHeight;
        addChild(_tf);

        var localConnection:LocalConnection = new LocalConnection();
        localConnection.addEventListener(StatusEvent.STATUS, handleConnectionStatus);
        localConnection.addEventListener(AsyncErrorEvent.ASYNC_ERROR, handleAsyncError);
        localConnection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, handleSecurityError);
        _tf.appendText("Creating local connection\n" + localConnection.domain + "\n");
        localConnection.send("_myConnection", "testMethod", "Hello world!");
    }

    private function handleSecurityError(e:SecurityErrorEvent):void
    {
        _tf.appendText("handleSecurtityError\n");
        _tf.appendText(e.text + "\n");
    }

    private function handleAsyncError(e:AsyncErrorEvent):void
    {
        _tf.appendText("handleAsyncError\n");
        _tf.appendText(e.error.message + "\n");
    }

    private function handleConnectionStatus(e:StatusEvent):void
    {
        _tf.appendText("handleConnectionStatus\n");
        _tf.appendText(e.code + "\n");
        _tf.appendText(e.level + "\n");
    }


}

}

我运行AIR应用程序,然后运行SWF,但SWF只打印出"错误"对于事件的级别属性。我在网上阅读的所有内容都说这应该有效。我尝试在localhost和实际网站上运行SWF,它的行为方式相同。

0 个答案:

没有答案