2011-07-26 69 views
1

不知道我哪裏錯了,現在只是在本地嘗試。謝謝。AS3本地連接錯誤

sendingLC.swf不返回,調用LocalConnection.send()成功

這是我從Flash得到了錯誤。 錯誤#2044:未處理的AsyncErrorEvent :. text =錯誤#2095:flash.net.LocalConnection無法調用回調myMethod。錯誤= ReferenceError:錯誤#1069:在flash.net.LocalConnection上找不到屬性myMethod,並且沒有默認值。

代碼sendingLC.swf:

import flash.net.LocalConnection 

var sendingLC:LocalConnection; 
sendingLC = new LocalConnection(); 
sendingLC.allowDomain('*'); 
Security.allowDomain("*"); 
sendBtn.addEventListener(MouseEvent.CLICK, sendIt); 

function sendIt(eventObj:MouseEvent):void { 
    sendingLC.send('myConnection', 'myMethod'); 
} 

sendingLC.addEventListener(StatusEvent.STATUS, statusHandler); 


function statusHandler (event:StatusEvent):void 
{ 
    switch (event.level) 
    { 
     case "status" : 
      textArea.text = ("LocalConnection.send() succeeded"); 
      break; 
     case "error" : 
      textArea.text = ("LocalConnection.send() failed"); 
      break; 
    } 
} 

代碼receivingLC.swf:

import flash.net.LocalConnection 

var receivingLC:LocalConnection; 
receivingLC = new LocalConnection(); 
receivingLC.allowDomain('*'); 
Security.allowDomain("*"); 
receivingLC.connect('myConnection'); 

function myMethod():void {trace('Hello World')} 
+0

你在什麼時候調用sendIt函數?這兩個swf的加載? –

+0

我打開這兩個瑞士法郎,然後點擊sendBtn,它調用sendIt – Chuck

+0

他們是否在瀏覽器中打開? –

回答

0

在接收器中建立連接可能存在問題。

try { 
    var receivingLC:LocalConnection; 
    receivingLC = new LocalConnection(); 
    receivingLC.allowDomain('*'); 
    Security.allowDomain("*"); // not sure this line is needed 
    receivingLC.connect('myConnection'); 
} catch (error:ArgumentError) { 
    trace('failure to make connection ' + error.toString()); 
} 

也未嘗要注意不要在閃存API測試LocalConnections做到這一點通過瀏覽器,當你第一次做這些的權限問題可以是一個胡思亂想的女人。

+0

所以我最終只是有一段時間來嘗試一下你的建議,現在我正在瀏覽器中進行測試,在最後的實現中,每個swf都將在單獨的iFrame內部,這就是我正在測試的方式。當我在本地進行測試時,我仍然得到相同的錯誤,沒有額外的輸出。謝謝 – Chuck

+0

嘗試發送LC.send('_ myConnection','myMethod');並接收LC.connect('_ myConnection'); –

+0

下劃線確實有意義 –

0

也許嘗試使myMethod公共像這樣:

public function myMethod():void{ 
    trace("hello world"); 
} 

你也應該嘗試/趕上發送電話,以便獲得更多有關如下錯誤的信息:

try{ 
    sendingLC.send('myConnection', 'myMethod'); 
} 
catch(e:Error){ 
    trace(e.toString()); 
} 
+0

我嘗試了try/catch,因爲你擁有它,但是我得到了1046:未找到類型或者不是編譯時常量:異常。我之前沒有使用過try/catch,所以我不得不更多地研究它。謝謝 – Chuck

+0

哈哈對不起,這是e:錯誤不是e:異常。 –

2

我也有問題與LocalConnection給我回調錯誤,但它停止時,我將客戶端屬性添加到連接。然後它開始工作,即使在閃存IDE中。

var conn:LocalConnection; 
conn = new LocalConnection(); 
conn.allowDomain('*'); 
conn.client = this; 
conn.connect('localThingieConnector');