I'm attempting to run a SWF in a browser and have it communicate to an AIR application that is bundled as an exe for windows.
In my AIR app (the receiver) I have the following
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");
}
}
}
And in the sender, the SWF on the web I have
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");
}
}
}
I run the AIR app and then I run the SWF, but the SWF just prints out "error" for the event's level property. Everything I'm reading online says this should work. I try to run the SWF on localhost and from an actual website and it acts the same either way.