Access flex application through the SWFLoader component

As you know, I’m a web developer and I love learning new stuff and blogging about it here. My blog post for today is about access flex application through the SWFLoader component.

Often you load flex applications through another flex application using the SWFLoader component.

It’s not that common knowledge that you can actually access all of that application exactly the same way you are accessing your own application.

What does that mean?

It means you can access that application components, get the children and get a good knowledge on how this application is build. You can also access it’s component and dispatch events.

OK, how?

Let’s start doing it. We will create a simple application, put a SWFLoader on stage and create a listener for the complete event.

Lets’s also add 2 global variables – one for SystemManager, another for IUIComponent (I will explain later).

This is what the application code should look like:

[actionscript3]

<?xml version=“1.0” encoding=“utf-8”?>

mx:Script

/mx:Script

/mx:Application

[/actionscript3]

As you can probably see, we are assigning a value to _systemManager when the loader (SWFLoader) finished loading. This enables us to work with that application system Manager and access properties.

Continuing…

We will add 2 Event listeners inside that function:

[actionscript3]

_systemManager.addEventListener(FlexEvent.APPLICATION_COMPLETE, sysManage_ApplicationComplete_Handler);

_systemManager.addEventListener(FlexEvent.UPDATE_COMPLETE, sysManage_UpdateComplete_Handler);

[/actionscript3]

Now that we have those in place, let’s add the closure functions:

[actionscript3]

private function sysManage_UpdateComplete_Handler(event:FlexEvent):void

{

_innerApplication = _systemManager.application;

}

private function sysManage_ApplicationComplete_Handler(event:FlexEvent):void

{

_innerApplication = _systemManager.application;

}

[/actionscript3]

Great! Now _innerApplication is actually an application. You can get it’s children, get properties, get components, dispatch events and more.

This comes in very handy when you want control over an application and you don’t have the source. You can create a clone of that application and create your own GUI for it. It’s an amazing feature!

This here is a screenshot of debugging mode. Check out the debugger watch section, these are all methods you can use on that variable, you can of course use much more.

Debug view of the application in Flash builder 4

Good luck!

Submit to Hacker News

[NOTE] This post has been imported to Hugo from a Wordpress blog. It may be broken, missing images, code snippets or other information.

[NOTE] updated May 30, 2010. It's 3165 days old . This article may have outdated content.