1

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')}
Chuck
  • 375
  • 5
  • 22

3 Answers3

2

I also had issues with the LocalConnection giving me callback errors, but it stopped when I added the client property to the connection. Then it started working, even in flash IDE.

var conn:LocalConnection;
conn = new LocalConnection();
conn.allowDomain('*');
conn.client = this;
conn.connect('localThingieConnector');
exa42
  • 91
  • 1
  • 2
0

Perhaps try making myMethod public like so:

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

Also you should try/catch the send call so you get more information about errors like so:

try{
  sendingLC.send('myConnection', 'myMethod');
}
catch(e:Error){
  trace(e.toString());
}
citizen conn
  • 15,300
  • 3
  • 58
  • 80
  • I tried try/catch as you have it, but I get 1046: Type was not found or was not a compile-time constant: Exception. I've not used try/catch before so I'll have to look into it more. Thanks – Chuck Jul 26 '11 at 19:15
0

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.

The_asMan
  • 6,364
  • 4
  • 23
  • 34
  • So I finally just had some time to try out what you had suggested, I am now testing within a browser, in the final implementation each swf will be inside seperate iFrames, so that is how I'm testing. I still get the same errors as when I was testing locally, with no additional output. Thanks – Chuck Aug 05 '11 at 19:41
  • try sendingLC.send('_myConnection', 'myMethod'); and receivingLC.connect('_myConnection'); – The_asMan Aug 05 '11 at 21:20
  • The underscore does have a meaning – The_asMan Aug 05 '11 at 21:21