Apr 06
Window Manager in AIR
I was actually surprised that something like this hasn’t come in the sdk with AIR 1.0 release. I built this during the AIR beta and adjusted it now to run on 1.0. It acts as a global window manager and manages all your window instances in an Air application.
It uses SimpleWindow class which extends mx.core.Window and adds some needed functionalities.
For the ones interested in the ways things work here’s an image which speaks better english.
A short example of how it should be used.
First, create a window component extending SimpleWindow. Let’s say MyWindow.mxml:
<?xml version="1.0" encoding="utf-8"?>
<core:Simplewindow>
xmlns:core="com.flexwizz.core.*"
xmlns:mx="http://www.adobe.com/2006/mxml"
width="400" height="300"
title="My Window">
<mx:Text width="100%" text="I am MyWindow">
</mx:Text>
</core:Simplewindow>
Then you can simply use WindowManager.openWindow(MyWindow) . Simple enough…
I often needed to restrict more then 1 windows of a specific type to be opened at once. And you can achieve that pretty simple here by specifying the windowUID on that component above. The property windowUID should always be set on component declaration, must be a const (binding isn’t made here) and before opening it with WindowManager. Example (MyWindow.mxml):
MXML:
<?xml version="1.0" encoding="utf-8"?>
<core:Simplewindow>
xmlns:core="com.flexwizz.core.*"
xmlns:mx="http://www.adobe.com/2006/mxml"
width="400" height="300"
title="My Window"
windowUID="com.wins::MyWindow">
<mx:Text width="100%" text="I am MyWindow">
</mx:Text>
</core:Simplewindow>
And open it:
WindowManager.openWindow(MyWindow)
When you try to open a 2nd window with the same windowUID, WindowManager will activate the window that is already opened with that windowUID. Or you can specify it to notify that the window is already opened which can be done using the 3rd argument of the openWindow methods.
You can use any string on windowUID property and the WindowManager will never open 2 instances with the same windowUID. But actually, the way I thought it, if you want to easily keep track of your windows in the application you can set this property to package+”::”+ClassName string as I did above in the MyWindow component. This way you can easily use getQualifiedClassName(ClassName) to get the windowUID of that. For example for MyWindow.mxml:
WindowManager.getOpenedWindow(getQualifiedClassName(MyWindow); // returns the window's instance
Anyways, there is a example application + source-code which explains all the functionalities better.
You can get the recommended Example Application - Air file included, the Lib SWC, Lib Source and AsDocs.
Btw, you should also check the code license page.
Hope this helps! and let me know if it’s useful or if you run into trouble, find bugs, etc.


April 6th, 2008 at 10:12 am
cool!
will try that out.
btw - there has been another try to realize a window manager: http://blog.everythingflex.com/2008/02/26/everythingflexair1swc-introduces-superwindow/
April 6th, 2008 at 1:00 pm
“I was actually surprised that something like this hasn’t come in the sdk with AIR 1.0 release.”
yeah, me too. the official word I got was that the AIR framework would provide enough low level stuff for the community to then take and run with (which you have - many thanks for the hard work)
the interesting thing is that window managers have been provided by Windows all the way back (as far a I can remember) VisualBasic3.0.
does it worry you that there might be a duplication of effort in different implementations? I mean, for the rest of us we just need a window manager that is predictable to implement and simply works.
April 6th, 2008 at 2:16 pm
“does it worry you that there might be a duplication of effort in different implementations?”
No, not at all. The thing is that I created this to suit my needs and will continue to update it as soon as my needs expand or somebody who uses it needs something added/fixed and I find it right to do so. Haven’t got the chance but I will check out what else is there and most importantly to see if the results are similar. Who knows, maybe they can go together or even joined… I’m always opened for suggestions.
May 16th, 2008 at 1:10 am
[…] AIR中没有对窗口进行良好管理的类,该作者写了一个windowManager来管理打开的窗口(mx.core.Window): Window Manager in AIR […]
May 23rd, 2008 at 12:56 am
Very useful.
Thanks.