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:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600">
	<mx:Script>
		<![CDATA[
			import mx.core.IUIComponent;
			import mx.managers.SystemManager;

			private var _systemManager:SystemManager;
			private var _innerApplication:IUIComponent;

			protected function loader_completeHandler(event:Event):void
			{
				_systemManager = SystemManager(loader.content);
			}
		]]>
	</mx:Script>

	<mx:SWFLoader id="loader" source="VistaRemix.swf" width="800" height="600" autoLoad="true" complete="loader_completeHandler(event)"/>
</mx:Application>

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:

_systemManager.addEventListener(FlexEvent.APPLICATION_COMPLETE, sysManage_ApplicationComplete_Handler);
_systemManager.addEventListener(FlexEvent.UPDATE_COMPLETE, sysManage_UpdateComplete_Handler);

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

			private function sysManage_UpdateComplete_Handler(event:FlexEvent):void
			{
				_innerApplication = _systemManager.application;
			}

			private function sysManage_ApplicationComplete_Handler(event:FlexEvent):void
			{
				_innerApplication = _systemManager.application;
			}

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!

Flash builder 4 – sharing a project with your team using SVN Screencast

Wish to know how to share a project with your team using SVN and Flash Builder 4? In this post I will show you just that!

But before watching my screencast, I wish to tell you something a bit personal. This is my first screencast in English, after quite a few in my native tongue language. so please excuse me if I stutter or swallow some of my words. I promise to keep getting better with time.

Continue reading

Change WebOrb default port from 2037 to what you want

I’ve been using WebOrb for almost a year now. Sometimes it’s a great experience, sometimes less (like any other product I have ever used).

I have been running production machines for a client. This client request to test the WebOrb service on another port other then 2037 (default).
It’s actually quite simple to create, but not intuitive.

If you are using WebOrb from the command line, you have a setting called “port”. All you have to do is run the command with the port param and everything will work great.

Like so:

c:\inetpub\wwwroot\weborb30\weborbee.exe -port 1935