4 Replies Latest reply on Jan 29, 2009 4:09 PM by fypstudent

    Adobe Flash Air Application

    fypstudent Level 1
      Hi,

      I try to do an Flash Air application which is able to minimize to the system tray when I click on the minimize button. Currently, I am able to minimize it to the window task bar but unable to minimize it onto the system tray showing the icon.

      I tried to search tutorials online and found is mostly using Flex instead of Flash. I somehow tried to use the codes given but there were many errors faced.

      I found one which is used Flash to minimize the icon into the system tray:
      http://www.adobe.com/devnet/air/flash/quickstart/stopwatch_dock_system_tray.html

      However, this is minimizing the clock image what is shown on the big image, what I wanted to do is to load an logo.png from my images folder. Can anyone help?


      Codes:

      ///////////canvas.as////////////////////////////
      package{

      import flash.display.MovieClip;
      import applications.controls.*;
      import flash.desktop.DockIcon;
      import flash.desktop.NativeApplication;
      import flash.desktop.SystemTrayIcon;
      import flash.display.NativeMenu;
      import flash.display.NativeMenuItem;
      import flash.events.InvokeEvent;
      import flash.events.MouseEvent;
      import flash.events.Event;
      import flash.display.Loader;



      public class canvas extends MovieClip {

      private var imageURLs:Array = ['icons/logo16.png',
      'icons/logo32.png',
      'icons/logo48.png',
      'icons/logo128.png'];

      public var biffMenu:menu;
      public var closeButton:CloseButton = new CloseButton(5);
      public var minBtn:MinimizeButton;

      public function canvas() {

      biffMenu = new menu();
      addChild(biffMenu);


      addChild(closeButton);
      closeButton.x = 87;
      closeButton.y = 8;

      minBtn = new MinimizeButton;
      addChild(minBtn);
      minBtn.addEventListener(MouseEvent.CLICK, dock);

      if (NativeApplication.supportsSystemTrayIcon){
      var sysTrayIcon:SystemTrayIcon = NativeApplication.nativeApplication.icon as SystemTrayIcon;
      sysTrayIcon.tooltip = "AirBiff";
      sysTrayIcon.addEventListener(MouseEvent.CLICK,undock);
      }


      }//close of public function canvas

      public function dock(event:Event = null):void{
      stage.nativeWindow.visible = false;
      NativeApplication.nativeApplication.icon.bitmaps = [imageURLs.bitmapData];
      }

      public function undock(event:Event = null):void{
      stage.nativeWindow.visible = true;
      NativeApplication.nativeApplication.icon.bitmaps = [];
      }

      }//close pf public class canvas

      }//close of package




      /////////////MinimizeButton.as///////////////////////////////////

      package applications.controls
      {
      import flash.display.Sprite;
      import flash.events.MouseEvent;
      //import flash.filters.DropShadowFilter;

      public class MinimizeButton extends Sprite
      {
      public function MinimizeButton(){

      with (graphics){
      beginFill(0xffffff,1);
      drawRect(75,9,5,2);

      }
      buttonMode = true;
      addEventListener(MouseEvent.CLICK, onClick);

      }

      private function onClick(e:MouseEvent):void{
      stage.nativeWindow.minimize();
      }

      }
      }
        • 1. Re: Adobe Flash Air Application
          Joe ... Ward Level 4
          This line is wrong:
          NativeApplication.nativeApplication.icon.bitmaps = [imageURLs.bitmapData];

          imageURLs is an array of file names. You need to load these images and then place the loaded bitmapData objects into an array. You can then assign that array to the icon.bitmaps property.

          You can find an example of this in the following article:
          http://www.adobe.com/devnet/air/flash/quickstart/adding_menus.html
          • 2. Re: Adobe Flash Air Application
            fypstudent Level 1
            Hi,

            Thanks for the help. I'm able to solve the problem. I am able to minimize it to the tray and the window would disappear, just showing the little icon in the system tray. However, when I click on the icon in the tray again, the taskbar button does appear but the window is minimize. I have to click on the taskbar button to allow the window to be open. How do you solve this problem by just clicking on the icon in the tray and the window will just appear at the screen but not minimize at the taskbar?

            I tried to combine the codes of the link you gave me and the codes I got and this is what I have done:

            Codes:

            package{

            import flash.display.MovieClip;
            import applications.controls.*;

            import flash.desktop.DockIcon;
            import flash.desktop.NativeApplication;
            import flash.desktop.SystemTrayIcon;
            import flash.display.NativeMenu;
            import flash.display.NativeMenuItem;
            import flash.display.NativeWindow;
            import flash.display.NativeWindowInitOptions;
            import flash.events.NativeWindowBoundsEvent;
            import flash.display.NativeWindowSystemChrome;
            import flash.events.MouseEvent;
            import flash.events.Event;
            import flash.events.InvokeEvent;

            public class canvas extends MovieClip {


            public var biffMenu:menu;
            public var closeButton:CloseButton = new CloseButton(5);
            public var minBtn:MinimizeButton;
            public var alias:userAlias;

            private var icon:AIRMenuIcon = new AIRMenuIcon();
            private var window:NativeWindow;
            private var application:NativeApplication = NativeApplication.nativeApplication;


            public function canvas() {

            addEventListener(Event.ADDED_TO_STAGE, initialize);

            biffMenu = new menu();
            addChild(biffMenu);

            alias = new userAlias;
            addChild(alias);
            alias.y = 28;

            addChild(closeButton);
            closeButton.x = 87;
            closeButton.y = 8;

            minBtn = new MinimizeButton;
            addChild(minBtn);


            minBtn.addEventListener(MouseEvent.CLICK, dock);


            }/////////close of public function canvas/////////////////


            private function initialize(event:Event):void{

            trace("INITIALIZING!!!");

            if(NativeApplication.supportsDockIcon){

            var dockIcon:DockIcon = NativeApplication.nativeApplication.icon as DockIcon;
            NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE,undock);
            }

            if(NativeApplication.supportsSystemTrayIcon){

            var sysTrayIcon:SystemTrayIcon = NativeApplication.nativeApplication.icon as SystemTrayIcon;
            sysTrayIcon.tooltip = "AirBiff";
            sysTrayIcon.addEventListener(MouseEvent.CLICK,undock);

            }
            }

            public function dock(e:MouseEvent):void{
            stage.nativeWindow.visible = false;
            icon.addEventListener(Event.COMPLETE,function():void{
            application.icon.bitmaps = icon.bitmaps;
            });
            icon.loadImages();

            }

            public function undock(event:Event = null):void{
            stage.nativeWindow.visible = true;
            NativeApplication.nativeApplication.icon.bitmaps = [];
            }



            /** Creates and returns a NativeMenu object **/
            private function createRootMenu(menuType:String):NativeMenu{
            var menu:NativeMenu = new NativeMenu();
            //menu.addSubmenu(createFileMenu(menuType),"File");
            //menu.addSubmenu(createEditMenu(menuType),"Edit");
            return menu;
            }


            }//close of public class canvas

            }//close of package
            • 3. Re: Adobe Flash Air Application
              Joe ... Ward Level 4
              Setting the window visible property won't change the window display state so I can't tell why your window is reappearing in the minimized display state.

              Is something in the MinimizeButton class changing the window display state? If so to solve the problem, you can either remove the code that sets the window to the minimized state, or use the NativeWindow restore() function in your undock() function.
              • 4. Re: Adobe Flash Air Application
                fypstudent Level 1
                I tried to change the codes to stage.NativeWindow.restore(); however i'm still facing the same problem. I'm not really sure if it is my minimizeButton.as problem.

                This is the codes for minimizeButton.as:

                package applications.controls
                {
                import flash.display.Sprite;
                import flash.events.MouseEvent;
                //import flash.filters.DropShadowFilter;

                public class MinimizeButton extends Sprite
                {
                public function MinimizeButton(){

                with (graphics){
                beginFill(0xffffff,1);
                drawRect(75,9,5,2);

                }
                buttonMode = true;
                addEventListener(MouseEvent.CLICK, onClick);

                }

                private function onClick(e:MouseEvent):void{
                stage.nativeWindow.minimize();
                }

                }
                }

                what i make changes in canvas.as

                public function undock(event:Event = null):void{
                //stage.nativeWindow.visible = true;
                stage.nativeWindow.restore();
                NativeApplication.nativeApplication.icon.bitmaps = [];
                }