Friday, November 28, 2008

Multiple window in AIR application

This piece of code gives a brief idea of how to work with multiple window. Invoking an application(mxml) from other applications(mxml).This piece is different from pop up window. Pop up window is a pre-defined class while creating a window application is user defined application.

In this example, I am calling ChildWindow.mxml from ParentWindow.mxml.

Call child Window
ParentWindow
in "<mx:Script>" section of the ParentWindow, create an instance of the ChildWindow, initialize and open the window.

Declare the intance of the child
private var newChild:ChildWindow;

initialize the instance
newChild= new ChildWindow();

to open the window
newChild.open();

ChildWindow
ChildWindow should be of Window component type ()

To pass variable from parent to child
declare the variable in the ChildWindow. When creating the instance, initialize the variable from the mainwindow. For example, to pass the value "yaazh" to the variable "name" of the child window, the code is given below

in ChildWindow
declare variable name in "<Script>"
section public var name:String

in ParentWindow when creating intance of the ChildWindow, assign the value to the variable of the ChildWindow instance.

newChild= new ChildWindow();
newChild.name="yaazh";
newChild.open();

this will work :-)

No comments: