6 Replies Latest reply on Apr 28, 2009 6:29 PM by tedalde2

    Getting system tray click working

    Shawazi
      Ive tried this:

      var sysTrayIcon = air.NativeApplication.nativeApplication.icon;
      sysTrayIcon.bitmaps = new runtime.Array(event.target.content.bitmapData);
      sysTrayIcon.addEventListener(air.click, restoreApp);

      in place of air.click I have tried Event.click, Event.CLICK, MouseEvent.click, MouseEvent.CLICK and many other options I've come across in the forums but I can't seem to find the proper one. Can anyone help out on this one? I am an HTML/AJAX developer and the only major differnece I have seen between the forums is in a lot of cases I use air.NativeApplication.nativeApplication instead of NativeApplication.nativeApplication.
        • 1. Getting system tray click working
          Shawazi Level 1
          Oh the error message is:

          TypeError: Can't get property CLICK from undefined value

          This is even from air.MouseEvent.CLICK
          • 2. Re: Getting system tray click working
            LemonairePaides
            Try something like the below:

            air.NativeApplication.nativeApplication.icon.addEventListener("mouseDown", restoreApp);
            • 3. Re: Getting system tray click working
              Shawazi Level 1
              wow putting the event in quotes was the only thing i did not try or find on the forums. i had found a guy who said that all he needed to do was use click, but i thought he meant as an object. so i put "click" instead of "mouseDown" and it works all the same. i wish that was in the docs somewhere that for the tray you use strings instead of objects
              • 4. Getting system tray click working
                Joe ... Ward Level 4
                The addEventListener() function takes a string. The "objects" typically used with this function are string constants. In other words, MouseEvent.CLICK is a string constant with the value "click". In a strongly typed language, such as ActionScript 3, using a constant has significant benefits. In JavaScript, there are fewer advantages.

                In an AIR application, when you want to reference an AIR class from JavaScript, you technically have to provide the fully qualified name of the class. Thus the proper way to access the single NativeApplication object in JavaScript is:
                window.runtime.desktop.NativeApplication.nativeApplication.

                Now what about that "air." prefix, you ask? Well to make things a bit easier, so you don't have to type long strings for every AIR object reference, the AIR SDK includes the AIRAliases.js file. This file includes aliases, or shortcuts for many (but not all) of the built-in AIR classes. For example, you can use air.NativeApplication.nativeApplication because of this line in the file:
                air.NativeApplication = window.runtime.flash.desktop.NativeApplication;

                To use these shortcuts, you must include the AIRAliases.js file in your HTML page using a script tag.

                Mouse event constants for click, mouseDown, etc, are defined in the MouseEvent class. The relevant line in the aliases file is:
                air.MouseEvent = window.runtime.flash.events.MouseEvent;

                So the way to use the mouse event type constants is the following:
                air.MouseEvent.CLICK
                air.MouseEvent.MOUSE_DOWN

                BTW, the convention for the string values of the event type names is that the string is the camel case version of the constant name (without underscores). Thus MouseEvent.MOUSE_DOWN == "mouseDown".
                • 5. Re: Getting system tray click working
                  Buch90

                  Hi

                  What does your restore app function look like? I'd like to use it but I have tried using

                  window.nativeWindow.maximize(); but then my app just break since i use custom chrome.

                   

                  Best Regards

                  Buch

                  • 6. Re: Getting system tray click working
                    tedalde2 Level 2

                    I just created something similar and successfully used NativeWindow.activate and NativeApplication.activate to restore the main app. Note that you cannot re-open closed windows, and if Mac, the Dock icon will not dispatch a CLICK event.  Instead for the Dock listen for the NativeApplication INVOKE event. You may also need to investigate the use of NativeApplication.autoExit.