首页 > 其他 > 详细

LocalConnection

时间:2021-06-12 00:45:40      阅读:26      评论:0      收藏:0      [点我收藏+]

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");
}

  

LocalConnection

原文:https://www.cnblogs.com/dt1991/p/14876077.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!