Как отправить текстовый файл между приложениями air, используя локальное соединение?
Отправитель AIR
private var conn: LocalConnection;
public function init():void
{
conn=new LocalConnection();
conn.addEventListener(StatusEvent.STATUS,onStatus);
}
private function Sender():void {
var alphabets:File= File.createTempFile();
var file:FileStream = new FileStream();
file.open(alphabets,FileMode.WRITE);
file.writeUTFBytes("Have a nice day");
file.close();
conn.send("app#ReceiverAIR:MyConnection", "lcHandler",t1.text,alphabets);
}
private function onStatus(event:StatusEvent):void {
switch (event.level) {
case "status":
trace("LocalConnection.send() succeeded");
break;
case "error":
trace("LocalConnection.send() failed");
break;
}
}
]]>
</fx:Script>
<mx:TextArea id="t1" />
<mx:Button id="b1" label="Send" click="Sender()" />
Приемник AIR
import flash.net.LocalConnection;
import mx.collections.ArrayCollection;
private var conn:LocalConnection;
public function LocalConnectionReceiverExample() {
conn = new LocalConnection();
conn.client = this;
try {
conn.allowDomain('app#SenderAIR');
conn.connect("MyConnection");
} catch (error:ArgumentError) {
trace("Can't connect...the connection name is already being used by another SWF");
}
}
public function lcHandler(msg:String,myfile:File):void {
trace("i am in lcHandler");
t1.text=msg;
}
]]>
</fx:Script>
<mx:TextArea id="t1" editable="false"/>
Выдает следующую ошибку
Error #2044: Unhandled AsyncErrorEvent:. text=Error #2095:
flash.net.LocalConnection was unable to invoke callback lcHandler.
error=TypeError: Error #1034:
Type Coercion failed:
cannot convert Object@83d6791 to flash.filesystem.File.