Flex AS3 Swf to Swf Communication via LocalConnection

1 Comment

I needed to get A Flex application to have a 2 way communication to an embedded Flex app. The examples I found on the interweb were either 1 way or focused on Flash. Also, some of the samples on the net kept giving me this error –

Error #2082: Connect failed because the object is already connected.

Here’s the basics:

Sending a message is pretty easy. I’ve instantiated a LocalConnection called connection. To send messages, I call the send method. The arguments are the connection name, the method in the child swf that will be invoked, and the data to pass.

// receivedParentPingMethod is a function defined in the Child swf
connection.send("fromParent", "receivedParentPingMethod", txtSend.text);

To receive stuff from the child, you need to do 2 things:

//open a connection and listen to it

Create a function on the parent

//define a function that will be called from the child swf
// receivedChildPingMethod will get called from the Child
public function receivedChildPingMethod(msg:String):void {
        txtResult.text += "Received ping from child:\n"+msg+"\n\n";

You then do the same for the child. This is the caveat however. You can’t listen on the same connection for the child because that will throw said error. You’ll have to create a new connection and listen in on that. Something like this:

// listen to events from the parent

This part wasn’t obvious to me and was throwing me off.

Anywho, here’s the project. Enjoy.

Popularity: 12% [?]

Flex E4X XML Filtering


I couldn’t find much information about E4X filtering on the net. The problem that I had was I had a list of people, some of which were contractors, most of which were employees. The contractors simply did not have certain attributes and I could not filter this at the web service or SQL level for one reason or another. Mostly for lack of access. I finally figured out the problem and I figure that I should just jot it down for future reference.

Here’s the xml from the event handler once it was loaded:

var result_xml:XML = XML(event.result);

Are you ready for this? This was literally all I needed to do:

var resultList:XMLList = result_xml..node..node.(attribute(‘level’).toString() != "");

The attribute call looks for all nodes that have the attribute “level”, and just checks that it’s not an empty string.

That’s pretty much it.

Popularity: 6% [?]

Newer Entries