• Home
  • About Me
  • AIR Central
  • AS3 Libs
  • Books
  • Flex Central
  • Resources
  • The Guru's
  •  

    AIR ContextWindow

    Looking for an easy way to add window controls as a context menu to your AIR windows? Try my new ContextWindow class.

    cw.png
    ‘A’ music in Mp3. - visit this to download mp3 music
    If you didnt find desired track - visin high-quality music site and download it easily
    But if you wish to download mp3 track you can go to new mp3 music site

    OK, so this is not rocket science by any means, it is just a class that extends mx.core.Window and creates a NativeMenu within the constructor and assigns it to the contextMenu property. To use it, simply download the class and create an instance of it just as you would with the regular Window class.

    Here is a sample application file:

    <?xml version="1.0" encoding="utf-8"?>
    <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="absolute">

        <mx:Script>
            <![CDATA[
                import com.everythingflex.air.components.ContextWindow;
               
                private function createWindow():void{
                    var w:ContextWindow = new ContextWindow();
                    w.width=200;
                    w.height=100;
                    w.open();
                }
            ]]>
        </mx:Script>
        <mx:Button click="createWindow()" label="Create Wndow"
         horizontalCenter="0" verticalCenter="0"/>

    </mx:WindowedApplication>

    Here is the ContextWindow.as class file:

    package com.everythingflex.air.components
    {
        import flash.display.NativeMenu;
        import flash.display.NativeMenuItem;
        import flash.events.Event;
       
        import mx.core.Window;

        public class ContextWindow extends Window
        {
            public function ContextWindow():void{
                super();
                createMenu();
            }
            private function createMenu():void{
              var mainMenu:NativeMenu = new NativeMenu();
                    var minimizeMenu:NativeMenuItem = new NativeMenuItem("Minimize");
                    var maximizeMenu:NativeMenuItem = new NativeMenuItem("Maximize");
                    var restoreMenu:NativeMenuItem = new NativeMenuItem("Restore");
                    var closeMenu:NativeMenuItem = new NativeMenuItem("Close");
                    minimizeMenu.addEventListener(Event.SELECT, handleMenuClick);
                    maximizeMenu.addEventListener(Event.SELECT, handleMenuClick);
                    restoreMenu.addEventListener(Event.SELECT, handleMenuClick);
                    closeMenu.addEventListener(Event.SELECT, handleMenuClick);
                    mainMenu.addItem(minimizeMenu);
                    mainMenu.addItem(maximizeMenu);
                    mainMenu.addItem(restoreMenu);
                    mainMenu.addItem(closeMenu);
                    this.contextMenu=mainMenu;;
             }
             
             private function handleMenuClick(e:Event):void{
              var menuItem:NativeMenuItem = e.target as NativeMenuItem;
                    if(menuItem.label == "Minimize") this.minimize();
                    if(menuItem.label == "Maximize") this.maximize();
                    if(menuItem.label == "Restore") this.restore();
                    if(menuItem.label == "Close") this.close();
             }
        }
    }

    4 Responses to “AIR ContextWindow”

    1. swingguy Says:

      public class ContextWindow extends Window

      but why:
      ContextWindow can’t find open();

    2. everythingflex Says:

      Not sure, this works fine for me:

      var w:ContextWindow = new ContextWindow();
      w.open();

    3. Dean Verkühlen Says:

      Thank you for the comprehensive description and the free information.
      Best regards from http://www.webtechnik.net!

    4. Mirko Says:

      Thanks for all the different interesting articles. We like
      to visit your website and the diverse postings.

    Leave a Reply