Using the Window component

You can use a window in an application whenever you need to present a user with information or a choice that takes precedence over anything else in the application. For example, you might need a user to fill out a login window, or a window that changes and confirms a new password.

There are several ways to add a window to an application. You can drag a window from the Components panel to the Stage. You can also use call createClassObject() (see UIObject.createClassObject()) to add a window to an application. The third way of adding a window to an application is to use the PopUpManager class. Use the PopUpManager to create modal windows that overlap other objects on the Stage. For more information, see Window class.

Window component parameters

The following are authoring parameters that you can set for each Window component instance in the Property inspector or in the Component Inspector panel:

contentPath specifies the contents of the window. This can be the linkage identifier of the movie clip or the symbol name of a screen, form, or slide that contains the contents of the window. This can also be an absolute or relative URL for a SWF or JPG file to load into the window. The default value is "". Loaded content clips to fit the Window.

title indicates the title of the window.

closeButton indicates whether a close button is displayed (true) or not (false). Clicking the close button broadcasts a click event, but doesn't close the window. You must write a handler that calls Window.deletePopUp() to explicitly close the window. For more information about the click event, see Window.click.

You can write ActionScript to control these and additional options for Window components using its properties, methods, and events. For more information, see Window class.

Creating an application with the Window component

The following procedure explains how to add a Window component to an application. In this example, the window asks a user to change her password and confirm the new password.

To create an application with the Button component, do the following:

  1. Create a new movie clip that contains password and password confirmation fields, and OK and Cancel buttons. Name the movie clip PasswordForm.
  2. In the library, select the PasswordForm movie clip and select Linkage from the Options menu.
  3. Check Export for ActionScript and enter PasswordForm in the Identifier box.
  4. Enter mx.core.View in the class field.
  5. Drag a Window component from the Components panel to the Stage and delete the component from the Stage. This adds the component to the library.
  6. In the library, select the Window SWC and select Linkage from the Options menu.
  7. Check Export for ActionScript.
  8. Open the Actions panel, and enter the following click handler on Frame 1:
    buttonListener = new Object();
    buttonListener.click = function(){
      mx.managers.PopUpManager.createPopUp(_root, mx.containers.Window, true, { title:"Change Password", contentPath:"PasswordForm" })
    }
    button.addEventListener("click", buttonListener);
    

    This handler calls PopUpManager.createPopUp() to instantiate a Window component with the title bar "Change Password" that displays the contents of the PasswordForm movie clip.