Turns out there were a couple of problems with what I was doing.
I have a class that extends LocalConnection. Inside that class I had
declared the method "onConnection" to call when data is received.
Turns out that you have to assign the receiving method as a property of a
dynamic class, so I had 2 problems. The first was that my method was defined
in the class rather than being added as a mixin at runtime and the second
was that my wasn't declared dynamic which it needs to be to use mixins.
I'll file a bug.
Working AS 3 code below:
**********************************************
package {
import flash.util.trace;
import flash.display.Sprite;
import flash.events.*;
import flash.net.LocalConnection;
import flash.display.TextField;
import flash.text.StyleSheet;
import flash.text.TextFormat;
public var logField:TextField;
public class LocalConnectionExample extends Sprite {
private var connectionId:String = "_localconnection";
public var gateway:LocalConnectionGateway;
public function LocalConnectionExample() {
logField = new TextField();
logField.text = "";
logField.border = true;
logField.background = true;
logField.backgroundColor = 0xFFFFFF;
var format:TextFormat = new TextFormat();
format.font = "Verdana";
format.size = 5;
logField.defaultTextFormat = format;
addChild(logField);
gateway = new LocalConnectionGateway()
if(gateway.connect(connectionId)) {
gateway.onConnection = onConnection;
logField.text += "LocalConnection receiver\n";
} else {
logField.text += "LocalConnection sender\n";
logField.text += "Sending:: 'Test data'\n";
gateway.send(connectionId, "onConnection", "Test data");
}
}
public function onConnection(data:String) {
logField.text += "Data Received:: '" +data+ "'\n";
}
}
private dynamic class LocalConnectionGateway extends LocalConnection {
public function LocalConnectionGateway() {
logField.text += "Gateway created.\n";
addEventListener(StatusEventType.STATUS, onStatus);
addEventListener(SecurityErrorEventType.SECURITY_ERROR, onSecurityError);
}
private function onStatus(event:StatusEvent):Void {
logField.text += "onStatus: " + event + "\n";
}
private function onSecurityError(event:SecurityErrorEvent):Void {
logField.text += "onSecurityError: " + event.text + "\n";
}
}
}
***********************************************************
On 10/25/05, Spike <[EMAIL PROTECTED]> wrote:
>
> Yep,
>
> That works here.
>
> You've done a few things differently to what I had. That's why I
> originally thought it was AS 2.
>
> I'll poke around and see if I can isolate what was causing it to fail.
>
> Spike
>
> On 10/25/05, Spike <[EMAIL PROTECTED]> wrote:
> >
> > My bad,
> >
> > It is Flex 2.
> >
> > I'll give it a go here.
> >
> > Spike
> >
> > On 10/25/05, Spike < [EMAIL PROTECTED]> wrote:
> > >
> > > Thanks Muzak,
> > >
> > > The problem I'm having is in Flex 2 with Flash player 8.5 and
> > > ActionScript 3.
> > >
> > > That example looks like ActionScript 2 to me.
> > >
> > > Spike
> > >
> > > On 10/25/05, Muzak < [EMAIL PROTECTED]> wrote:
> > > >
> > > > Works fine here.
> > > >
> > > > Example from the docs:
> > > >
> > > > Sender.mxml:
> > > >
> > > > <?xml version="1.0" encoding="utf-8"?>
> > > > <mx:Application xmlns:mx=" http://www.macromedia.com/2005/mxml">
> > > >
> > > > <mx:Script>
> > > > public var lc:Object = new LocalConnection();
> > > > public function sendSymbol():Void {
> > > > public var symbol:String = ta1.text;
> > > > lc.send ("myConnection","showTickerSymbol",symbol);
> > > > }
> > > > </mx:Script>
> > > > <mx:TextArea id="ta1" text="ADBE"/>
> > > > <mx:Button label="Send Symbol" click="sendSymbol()"/>
> > > >
> > > > </mx:Application>
> > > >
> > > > Receiver.mxml:
> > > >
> > > > <?xml version="1.0" encoding="utf-8"?>
> > > > <mx:Application xmlns:mx=" http://www.macromedia.com/2005/mxml "
> > > > creationComplete="initApp()">
> > > >
> > > > <mx:Script>
> > > > public var lc:LocalConnection = new LocalConnection();
> > > > public function showTickerSymbol(param:String):Void {
> > > > message.text = "received: " + param;
> > > > }
> > > > public function initApp():Void {
> > > > lc.showTickerSymbol = showTickerSymbol;
> > > > lc.connect("myConnection");
> > > > }
> > > > </mx:Script>
> > > > <mx:Label text = "Receive Symbol"/>
> > > > <mx:TextArea id="message" text=""/>
> > > >
> > > > </mx:Application>
> > > >
> > > > regards,
> > > > Muzak
> > > >
> > > > ----- Original Message -----
> > > > From: "Spike" < [EMAIL PROTECTED]>
> > > > To: "Flashcoders mailing list" <[email protected] >
> > > > Sent: Tuesday, October 25, 2005 2:54 PM
> > > > Subject: [Flashcoders] LocalConnection in Flex 2
> > > >
> > > >
> > > > Has anyone got this working reliably?
> > > >
> > > > I'm getting either security exceptions or silent failures.
> > > >
> > > > Spike
> > > >
> > > >
> > > >
> > > > _______________________________________________
> > > > Flashcoders mailing list
> > > > [email protected]
> > > > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> > > >
> > >
> > >
> > >
> > > --
> > > --------------------------------------------
> > > Stephen Milligan
> > > Do you do the Badger?
> > > http://www.yellowbadger.com
> > >
> > > Do you cfeclipse? http://www.cfeclipse.org
> > >
> > >
> >
> >
> > --
> > --------------------------------------------
> > Stephen Milligan
> > Do you do the Badger?
> > http://www.yellowbadger.com
> >
> > Do you cfeclipse? http://www.cfeclipse.org
> >
> >
>
>
> --
> --------------------------------------------
> Stephen Milligan
> Do you do the Badger?
> http://www.yellowbadger.com
>
> Do you cfeclipse? http://www.cfeclipse.org
>
>
--
--------------------------------------------
Stephen Milligan
Do you do the Badger?
http://www.yellowbadger.com
Do you cfeclipse? http://www.cfeclipse.org
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders