1

不知道我哪里出错了,现在只是在本地尝试一下。谢谢。

sendLC.swf 确实返回,LocalConnection.send() 成功

这是我从 Flash 中得到的错误。错误 #2044:未处理的 AsyncErrorEvent:。text=Error #2095: flash.net.LocalConnection 无法调用回调 myMethod。error=ReferenceError:错误 #1069:在 flash.net.LocalConnection 上找不到属性 myMethod,并且没有默认值。

发送LC.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;
    }
}

接收LC.swf的代码:

import flash.net.LocalConnection

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

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

3 回答 3

2

我也遇到了 LocalConnection 的问题,给了我回调错误,但是当我将客户端属性添加到连接时它停止了。然后它开始工作,即使在 Flash IDE 中也是如此。

var conn:LocalConnection;
conn = new LocalConnection();
conn.allowDomain('*');
conn.client = this;
conn.connect('localThingieConnector');
于 2012-03-12T11:01:51.530 回答
0

也许尝试myMethod像这样公开:

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

此外,您应该尝试/捕获发送调用,以便获得有关错误的更多信息,如下所示:

try{
  sendingLC.send('myConnection', 'myMethod');
}
catch(e:Error){
  trace(e.toString());
}
于 2011-07-26T18:16:13.923 回答
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() );
}

还有一点需要注意的是,当你第一次做这些时,不要通过浏览器在 Flash api 中测试 LocalConnections,因为权限问题可能是一个脾气暴躁的女人。

于 2011-07-26T19:39:16.973 回答