Parent-child communication between flex applications

I have seen this question floating around with unsatisfactory answers from either Adobe or experts (no offense meant). This is NOT a localconnection solution. After hours of mucking around (developer cliche) here’s what I found …

Parent-to-child communication

To begin with refer to Adobe’s documentation on the SWFLoader control

The example in their case seems to work flawlessly because the child application is being loaded from the local filesystem. However, the same example applied to child applications loaded off the web fails miserably. I have seen quite a few flex dev’s out there frustrated with this problem. No, we are not discussing security issues here.

So, how does one accomplish this? Its easy as I found out the hard way …

  1. Make sure you are trying to access the child app only after it has loaded completely.
  2. You do NOT need to typecast the childApp’s SystemManager using mx.managers.SystemManager. This will most certainly lead to a type coercion error.
  3. The same applies to the the application instance of the child app.

Here’s some sample code on how to access the “public” members of the child app (assume childLoader is the ID of the SWFLoader component in use.

childLoader.content.application.{public member}

Child-to-parent communication

This was more of a hack since the localconnection connection kept “breaking” on the deployment machine which happens to run linux (custom version) which somehow never happened on the development machine (1 up for windoze I guess). If it works for you, disregard this approach.

The SWFLoader component has a hierarchy of objects before you actually get to the loaded content. The way a child application can see the parent application is through this code

Application.application.parent.parent.parent.parent.{public member}

parentApplication did not seem to work and thus the “hack” had to be implemented. Furthermore, Application.application seems to refer only to the current top level application, not the parent application via swfloader.

About thinkcap

PHP, MySQL, Flex, Flash, Actionscript, XML application developer. In my other life I spend time on photography, playing FPS games and trotting the web with StumbleUpon View all posts by thinkcap

Leave a comment