Search code examples
flashactionscript-3airnativewindow

AS3 AIR - NativeWindow pop-up box


In my AIR application, when a user creates a new project I want a pop-up box to appear where they can enter their project's name in. I understand how this is doable by making my own type of pop-up box, but is there a way to do this using NativeWindows? That is, can I make a window using the system chrome appear which contains a text field and a button?

I'm using Flex 4 and AIR 2.7 in FlashDevelop.


Solution

  • Yes you can. When creating a new NativeWindow you can add and remove children to its stage. So you could add your class / components to the new window and listen to their events.

    // create NativeWindowInitOptions
    var windowInitOptions:NativeWindowInitOptions = new NativeWindowInitOptions();
    windowInitOptions.type = NativeWindowType.NORMAL;
    windowInitOptions.minimizable = true;
    windowInitOptions.resizable = false;
    windowInitOptions.maximizable = false;
    windowInitOptions.systemChrome = NativeWindowSystemChrome.STANDARD;
    windowInitOptions.transparent = false;
    
    // create new NativeWindow
    var newWindow:NativeWindow = new NativeWindow(windowInitOptions);
    
    // create your class
    var popupBox:Sprite = new Sprite();
    
    // resize
    newWindow.width = popupBox.width;
    newWindow.height = popupBox.height;
    
    // add
    newWindow.stage.addChild(popupBox);
    
    // configure
    popupBox.addEventListener(YourCustomEvent.CONFIRM, onPopupConfirm);
    
    // for a popup it might be nice to have it activated and on top
    newWindow.alwaysInFront = true;
    newWindow.activate();
    

    Within the onPopupConfirm function you can close the Window and cleanup references. (Event.CLOSING on the NativeWindow, could come in handy for catching alt+F4 closing and such)