Вы можете достичь этого, используя 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);
}
Помните, что локальные соединения просты - связь является односторонней. Для двусторонней связи вы должны установить другую пару локальных соединений и вызвать connect
из соответствующего SWF с другим именем соединения.