ブラウザで 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");
}
}
}
送信者には、私が持っている Web 上の 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 と実際の Web サイトから SWF を実行しようとしましたが、どちらの方法でも同じように動作します。