2015-11-03 53 views
1

我想用LocalConnection連接兩個Air應用程序。它在我作爲SWF和EXE(已發佈)打開時起作用,但當我將它發佈到Air文件時,它們不起作用。我正在創建一個交互式屏幕,將命令發送給另一臺Air Application(投影儀)。這幾行代碼只會出現「第一幀」。空對空本地連接

發送:

接收:

var receiving_lc:LocalConnection; 
receiving_lc = new LocalConnection(); 
receiving_lc.connect("my_lc_as3"); 
receiving_lc.client = this; 

回答

2

請參閱本文檔http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/LocalConnection.html

爲了使AIR應用程序之間的LocalConnection工作中,allowDomain()需要被調用。 例如,你的情況:

// For receiving_lc 
// Here receiving_lc is an Air app with app Id = com.sample 
receiving_lc.allowDomain('app#com.example'); 
receiving_lc.connect("my_lc_as3"); 

// For sending_lc 
sending_lc.send('app#com.sample:my_conn', 'my_method'); 
+0

感謝您的回覆你好。 我沒有這個服務器,所以我在這個部分允許什麼(app#com.example)? –

+0

它應該是一個本地路徑。 – coner

+0

@CKLai'com.example'這裏只是你的AIR應用程序的ID。嘗試花時間閱讀[**從AIR應用程序到另一個AIR應用程序**](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/LocalConnection.html) ... – akmozo

0

謝謝KevinVFX和akmozo。

它現在正在工作,這是代碼。

發送:

var sending_lc:LocalConnection; 
sending_lc = new LocalConnection(); 
sending_lc.send("app#APPIDReceiving:my_lc_as3", "my_method"); 

接收:

var receiving_lc:LocalConnection; 
receiving_lc = new LocalConnection(); 
receiving_lc.allowDomain("app#APPIDSending"); 
receiving_lc.connect("my_lc_as3"); 
receiving_lc.client = this; 

function my_method():void{ 
trace("linked"); 
}