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

    ContextWindow

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

    eflex005.jpg

    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.

    Grab the SWC file here.

    This example creates an instance of a ContextWindow:

    1. private function createContextWindow():void{
    2.     var w:ContextWindow = new ContextWindow();
    3.     w.width=300;
    4.     w.height=200;
    5.     w.open();
    6. }

    The code below shows how to subclass ContextWindow as an MXML object:

    1. <?xml version="1.0" encoding="utf-8"?>
    2. <ContextWindow xmlns="com.everythingflex.air.components.*"
    3.     layout="absolute"
    4.     xmlns:mx="http://www.adobe.com/2006/mxml"
    5.     width="300" height="150">
    6.    
    7.     <mx:Label text="This is a ContextWindow"
    8.         horizontalCenter="0" verticalCenter="0" />
    9.    
    10. </ContextWindow>

    Here is the full sample code for this demonstration of the AlertWindow component.

    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 createContextWindow():void{
    9.                 var w:ContextWindow = new ContextWindow();
    10.                 w.width=300;
    11.                 w.height=200;
    12.                 w.open();
    13.             }
    14.            
    15.             private function openContextWindow():void{
    16.                 var w:Win1 = new Win1();
    17.                 w.open();
    18.             }
    19.         ]]>
    20.     </mx:Script>
    21.     <mx:Button click="createContextWindow()"
    22.         label="Create ContextWindow" x="150.5"
    23.         y="147" width="225"/>
    24.     <mx:Button click="openContextWindow()"
    25.         label="Open ContextWindow Component"
    26.         x="150.5" y="177" width="225"/>
    27. </mx:WindowedApplication>