Wiki

Clone wiki

dsair / WindowManager

HOWTO: WindowManager: Creating new windows

Introduction

The WindowManager helps make creating and controlling extra windows easier.

Details

Check out the TestWindowManager.as file for the full details.

As with all examples, you need to init the framework before doing anything:

#!actionscript

DSAir.init( this ); // "this" is your Document class

By default, any window created using the WindowManager is closed when the main app window closes.

Creating a window

Call the createWindow() function to create a new window:

#!actionscript

WindowManager.instance.createWindow( options:NativeWindowInitOptions = null, title:String = null, x:Number = -1.0, y:Number = -1.0, width:Number = 0.0, height:Number = 0.0, show:Boolean = true, giveFocus:Boolean = true );

All the parameters are optional. The default behaviour: * options: Standard chrome, normal window type, minimisable, maximisable, resizable * title: Goes "Untitled 1", "Untitled 2", etc * x and y: Indented from the top-left corner of the main window, with each subsequent new window being further indented. * width and height: 240x180 * show: The window is visible * giveFocus: The window takes away keyboard and mouse focus from the main window.

Centering windows

You can center windows on the main screen:

#!actionscript

WindowManager.instance.centerWindowOnScreen( window );

or on the main app window:

#!actionscript

WindowManager.instance.centerWindowOnApp( window );

Finding windows

You can get a specific window by calling:

#!actionscript

WindowManager.instance.getWindowByTitle( "Some window" );

Alert windows

You can use alert windows to show messages to the user:

#!actionscript

var alert:Alert = new Alert( "Some title", "This is the message to show" );

By default, an alert window has no buttons. You can add a button by calling:

#!actionscript

alert.addButton( "Close this", this._onClose, true ); // set last parameter to false to disable the button

Each button will close the alert, so you don't need to provide a callback.

To show or hide the alert, call:

#!actionscript

alert.show();

or

#!actionscript

alert.hide();

By default the alert is destroyed when it's closed. If you'd like to keep your alert to reuse it, set the destroyOnClose property to false.

Progress Alert

A subclass of the Alert window, the ProgressAlert is an alert that shows a progress bar at the same time.

To set or get the progress, you use the progress property:

#!actionscript

this.m_progress = new ProgressAlert( "Something's happening", "a message" );
this.m_progress.progress += 0.01;

It also has a property closeOnComplete (default false) that will automatically close the progress window when the progress is at 100%.

You can also provide an onComplete callback. It should take no parameters:

#!actionscript

this.m_progress.onComplete = this._onProgressComplete;
private function _onProgressComplete():void
{
    trace( "Complete!" );
}

Updated