Home > Flex > Communicating with a loaded Application in Flex 3.0

Communicating with a loaded Application in Flex 3.0

Communicating with a loaded flex application is not intuitive.  SWFLoader lets you load one Flex Application into another Flex Apllication as a SWF file. Once the SWF is loaded you can retrieve the SystemManager (class that manages an application window).

_objLoadedAppSystemManager = SystemManager(_objLoader.content);
trace(_objLoadedAppSystemManager.application) //null

The SystemManager’s ‘application’ property holds the reference to the application loaded. The problem is if you try to access this property once the SWF is loaded (by listening SWFLoader’s COMPLETE or INIT event) you will get null since the loaded ‘application’ didnt get initialized properly. One of the solution is to listen to the SystemManager’s APPLICATION_COMPLETE event.

_objLoadedAppSystemManager.addEventListener(FlexEvent.APPLICATION_COMPLETE, onLoadedAppInit);
...
...
private function onLoadedAppInit(objEvent:FlexEvent):void
{
	_objApplication = (_objLoadedAppSystemManager.application) as Object;
	_objApplication["functionname"](param);
}

Now you would be able to call the function (e.g. “functionname” as shown above). This function should be defined the main application file/class of the loaded application.

Categories: Flex Tags: ,
  1. April 18th, 2010 at 06:25 | #1

    I also covered this in a little bit more detail on my blog, and looked at casting the loaded Flex application to an Interface. Check it out herehttp://www.flexdaddy.com/2010/01/19/cast-a-loaded…

    • April 18th, 2010 at 08:52 | #2

      Thanks Andrew for the link. But the reason I didn't cast the Application is that the "Interface" file then need to be present/compiled in both the application (if the applications are part of two separate projects). So essentially there will be two interface files (same name) that need to be maintained. What would you recommend?

  1. No trackbacks yet.