actionscript-3localconnection

AS3 LocalConnection Errors


Not sure where I'm going wrong, for now just trying this out locally. Thanks.

sendingLC.swf does return, LocalConnection.send() succeeded

This is the errors I get from Flash. Error #2044: Unhandled AsyncErrorEvent:. text=Error #2095: flash.net.LocalConnection was unable to invoke callback myMethod. error=ReferenceError: Error #1069: Property myMethod not found on flash.net.LocalConnection and there is no default value.

Code for 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;
    }
}

Code for 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')}

Solution

  • There could be an issue with making the connection in the receiver.

    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() );
    }
    

    Also something to note do not test LocalConnections in the flash api do it through a browser when you are first making these as permission issues can be a cranky woman.