1 Reply Latest reply on Aug 19, 2009 12:58 PM by Vav

    AJAX/HTML Window Close Control

    Vav

      I want to implement system tray icon functionality. I have the system tray icon completed, however, once I close my main window, and try to use my system tray icon menu to exit the app, it fails with the response: "The application attempted to reference a JavaScript object in an HTML page that is no longer loaded." I can only assume that my window is closed, even though I thought I was intercepting the main window "closing" function with a function to make the window's visibility set to false via window.nativeWindow.visible = false. Here is my code:

       

      var iconLoadComplete = function(event){
           air.NativeApplication.nativeApplication.icon.bitmaps = [event.target.content.bitmapData];
      }
      air.NativeApplication.nativeApplication.autoExit = false;
      // I added the following ...
      window.nativeWindow.addEventListener(air.Event.CLOSING, hideWin);
      function hideWin(){
           window.nativeWindow.visible = false;
      };

      //
      var iconLoad = new air.Loader();
      var iconMenu = new air.NativeMenu();
      var exitCommand = iconMenu.addItem(new air.NativeMenuItem("Exit"));
      exitCommand.addEventListener(air.Event.SELECT,function(event){
           air.NativeApplication.nativeApplication.icon.bitmaps = [];
           air.NativeApplication.nativeApplication.exit();
      });
         

      if (air.NativeApplication.supportsSystemTrayIcon) {

           air.NativeApplication.nativeApplication.autoExit = false;
           iconLoad.contentLoaderInfo.addEventListener(air.Event.COMPLETE,iconLoadComplete);
           iconLoad.load(new air.URLRequest("icons/nis-logo_16.png"));
           air.NativeApplication.nativeApplication.icon.tooltip = "AIR App";
           air.NativeApplication.nativeApplication.icon.menu = iconMenu;  
      }
         
      if (air.NativeApplication.supportsDockIcon) {
           iconLoad.contentLoaderInfo.addEventListener(air.Event.COMPLETE,iconLoadComplete);
           iconLoad.load(new air.URLRequest("icons/nis-logo_128.png"));
           air.NativeApplication.nativeApplication.icon.menu = iconMenu;
      }

       

      Where am I going wrong?