AIR与AIR
发送方
ID :A
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.net.LocalConnection;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.events.StatusEvent;
import flash.text.TextFieldAutoSize;
var conn: LocalConnection;
LocalConnectionSenderExample();
function LocalConnectionSenderExample() {
sendBtn.addEventListener(MouseEvent.CLICK, sendMessage);
sendBtn2.addEventListener(MouseEvent.CLICK, sendMessage2);
sendBtn3.addEventListener(MouseEvent.CLICK, sendMessage3);
conn = new LocalConnection();
conn.addEventListener(StatusEvent.STATUS, onStatus);
}
function sendMessage(event: MouseEvent): void {
conn.send("app#B:myConnection", "lcHandler", message.text);
}
function sendMessage2(event: MouseEvent): void {
conn.send("app#C:myConnection", "lcHandler", message.text);
}
function sendMessage3(event: MouseEvent): void {
conn.send("app#B:myConnection", "lcHandler", message.text);
conn.send("app#C:myConnection", "lcHandler", message.text);
}
function onStatus(event: StatusEvent): void {
//trace(event)
switch (event.level) {
case "status":
trace("LocalConnection.send() succeeded");
break;
case "error":
trace("LocalConnection.send() failed");
break;
}
}
接收方:
ID:B
import flash.display.Sprite;
import flash.net.LocalConnection;
import flash.text.TextField;
var conn: LocalConnection;
LocalConnectionReceiverExample();
function LocalConnectionReceiverExample() {
conn = new LocalConnection();
conn.client = this;
conn.allowDomain("app#A");
try {
conn.connect("myConnection");
} catch (error: ArgumentError) {
trace("Can‘t connect...the connection name is already being used by another SWF");
}
}
function lcHandler(msg: String): void {
output.appendText(msg + "\n");
}
接收方:
ID:C
import flash.display.Sprite;
import flash.net.LocalConnection;
import flash.text.TextField;
var conn: LocalConnection;
LocalConnectionReceiverExample();
function LocalConnectionReceiverExample() {
conn = new LocalConnection();
conn.client = this;
conn.allowDomain("app#A");
try {
conn.connect("myConnection");
} catch (error: ArgumentError) {
trace("Can‘t connect...the connection name is already being used by another SWF");
}
}
function lcHandler(msg: String): void {
output.appendText(msg + "\n");
}
原文:https://www.cnblogs.com/dt1991/p/14876077.html