Creating an application with the Window component

The following procedure explains how to add a Window component to an application. In this example, when the user clicks a button the window displays an image.

To create an application with the Window component:

  1. Select File > New and choose Flash File (ActionScript 2.0).
  2. Drag a Window component from the Components panel to the current document's library. This adds the component to the library but not to the Stage.
  3. Drag a button component from the Components panel to the Stage; in the Property inspector, give it the instance name my_button.
  4. Open the Actions panel, and enter the following click handler in Frame 1:
    /**
     Requires:
      - Button component on Stage (instance name: my_button)
      - Window component in library
    */
    import mx.containers.Window;
    
    var my_button:mx.controls.Button;
    
    System.security.allowDomain("http://www.helpexamples.com");
    
    // Create listener object.
    var buttonListener:Object = new Object();
    buttonListener.click = function(evt_obj:Object) {
     // Instantiate Window.
     var my_win:MovieClip = mx.managers.PopUpManager.createPopUp(evt_obj.target, Window, true, {title:"Sample Image", contentPath:"http://www.helpexamples.com/flash/images/image1.jpg"});
     my_win.setSize(320, 240);
    };
    // Add listener.
    my_button.addEventListener("click", buttonListener);
    

    This example creates a click() function that the buttonListener event listener calls when the user clicks the button my_button. The click event handler, buttonListener.click(), calls PopUpManager.createPopUp() to instantiate a window that displays an image. To close the window when the OK or Cancel button is clicked, you would need to write another handler.