2010-01-22 104 views
0

你好,我是閃存的新手,我試圖做到以下幾點:調用閃存腳本的功能,從另一個Flash腳本

在一個閃存

頁劇本我想打電話給屬於另一個功能閃光腳本,如何做到這一點?

預先感謝您。

+0

是同一頁上的兩個swf嗎? – sberry

+0

不,他們屬於兩個不同的頁面 – andrea

+0

我的想法是加載其他頁面,然後調用我想調用的函數....我可以加載其他頁面...但後來我不知道如何調用功能... – andrea

回答

3

您可以使用LocalConnection來實現此目的。

接收SWF:

private var localConnection:LocalConnection 
//inside constructor 
{ 
    localConnection = new LocalConnection(); 
    //in case both SWF's are in different domains 
    localConnection.allowDomain("sender.swf's.domain"); 
    //in case receiver is in HTTPS and sender is non-HTTPS 
    localConnection.allowInsecureDomain("sender.swf's.domain"); 
    localConnection.connect("connectionName"); 
    localConnection.client = this; 

    //initialize TextField (tf) here 
} 
public function writeMsg(msg:String):void 
{ 
    tf.text += "\nReceived message\n" + msg; 
}  

發送SWF:

private var localConnection:LocalConnection; 
private var connectionName:String; 
//inside the constructor 
{ 
    connectionName = "connectionName"; //use the same name as in receiver 
    localConnection = new LocalConnection(); 
    localConnection.addEventListener(StatusEvent.STATUS, onStatus); 
    localConnection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecError); 
} 

//to call the "writeMsg" function in the receiver SWF from sender SWF 
localConnection.send(connectionName, "writeMsg", "It works!"); 

private function onStatus(e:StatusEvent):void 
{ 
    trace("statusEventHandler: code = " + e.code + ", level = " + e.level); 
} 
private function onSecError(e:SecurityErrorEvent):void 
{ 
    trace("unable to make LocalConnection due to Security Error: " + e.text); 
} 

記住本地連接單面 - 通信是單向的。對於雙向通信,您必須設置另一對本地連接,並使用不同的連接名稱從適當的SWF呼叫connect

+0

這真棒。這是我爲了在Flash對象內實現「與Facebook連接」工作流程所需的「缺失部分」... –

相關問題