Calendar

October 2007
M T W T F S S
« Sep   Nov »
1234567
891011121314
15161718192021
22232425262728
293031  

Tag Cloud

Categories

Archives

Highest Rated

Most Viewed

Recent Posts

Recent Comments


« UpdateManager Updated :-) | Main | RIA Developer Camp »

AIR ContextWindow

By Rich Tretola | October 18, 2007Print This Post Print This Post
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5 out of 5)
Loading ... Loading ...
676 views

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:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
  3.     layout="absolute">
  4.     <mx:Script>
  5.         <![CDATA[
  6.             import com.everythingflex.air.components.ContextWindow;
  7.  
  8.             private function createWindow():void{
  9.                 var w:ContextWindow = new ContextWindow();
  10.                 w.width=200;
  11.                 w.height=100;
  12.                 w.open();
  13.             }
  14.         ]]>
  15.     </mx:Script>
  16.     <mx:Button click="createWindow()" label="Create Wndow"
  17.      horizontalCenter="0" verticalCenter="0"/>
  18. </mx:WindowedApplication>

Here is the ContextWindow.as class file:

  1. package com.everythingflex.air.components
  2. {
  3.     import flash.display.NativeMenu;
  4.     import flash.display.NativeMenuItem;
  5.     import flash.events.Event;
  6.  
  7.     import mx.core.Window;
  8.  
  9.     public class ContextWindow extends Window
  10.     {
  11.         public function ContextWindow():void{
  12.             super();
  13.             createMenu();
  14.         }
  15.         private function createMenu():void{
  16.           var mainMenu:NativeMenu = new NativeMenu();
  17.                 var minimizeMenu:NativeMenuItem = new NativeMenuItem("Minimize");
  18.                 var maximizeMenu:NativeMenuItem = new NativeMenuItem("Maximize");
  19.                 var restoreMenu:NativeMenuItem = new NativeMenuItem("Restore");
  20.                 var closeMenu:NativeMenuItem = new NativeMenuItem("Close");
  21.                 minimizeMenu.addEventListener(Event.SELECT, handleMenuClick);
  22.                 maximizeMenu.addEventListener(Event.SELECT, handleMenuClick);
  23.                 restoreMenu.addEventListener(Event.SELECT, handleMenuClick);
  24.                 closeMenu.addEventListener(Event.SELECT, handleMenuClick);
  25.                 mainMenu.addItem(minimizeMenu);
  26.                 mainMenu.addItem(maximizeMenu);
  27.                 mainMenu.addItem(restoreMenu);
  28.                 mainMenu.addItem(closeMenu);
  29.                 this.contextMenu=mainMenu;;
  30.          }
  31.  
  32.          private function handleMenuClick(e:Event):void{
  33.           var menuItem:NativeMenuItem = e.target as NativeMenuItem;
  34.                 if(menuItem.label == "Minimize") this.minimize();
  35.                 if(menuItem.label == "Maximize") this.maximize();
  36.                 if(menuItem.label == "Restore") this.restore();
  37.                 if(menuItem.label == "Close") this.close();
  38.          }
  39.     }
  40. }

Share/Save/Bookmark

Topics: Adobe AIR, Components |

7 Responses to “AIR ContextWindow”

  1. swingguy Says:
    October 19th, 2007 at 9:33 pm

    public class ContextWindow extends Window

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

  2. everythingflex Says:
    October 22nd, 2007 at 12:32 pm

    Not sure, this works fine for me:

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

  3. Mirko Says:
    December 12th, 2007 at 11:38 am

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

  4. snipx Says:
    June 27th, 2008 at 7:27 am

    Is there a way to specify a context menu for the main application instead of one for a popup ? Thanks for this usefull article

  5. everythingflex Says:
    June 27th, 2008 at 8:17 am

    Yes, but not with this component. When you create a context menu, you can attach it to any object (Images, Panel, Boxes, etc).

  6. khan Says:
    August 11th, 2008 at 8:31 am

    please any body can help me in achieving the functionality of minimising and maximising the menu in flex with the same button??
    thanks in advance

  7. izmir evden eve Says:
    October 30th, 2008 at 7:44 am

    thanks.

Comments