0 Replies Latest reply on Dec 4, 2009 12:27 PM by tedalde2

    addSubmenuAt crashes the AIR app

    tedalde2 Level 2

      ...when attached to the system tray icon. If I add the menu, then click the tray icon, the app crashes. Check out the attached code. Looks like there's a workaround in that you can addSubmenu, then build menuitems after that. AIR v (Flash authoring) and (AIR SDK), Win XP.


      code for a blank FLA frame 1 with simple button intance bb on the stage:


      var ar:Array = new Array();
      var bmp:BitmapData = new BitmapData(26, 26, false, 0x88FF0099);
      ar[0] = bmp;
      NativeApplication.nativeApplication.icon.bitmaps = ar;

      var men:NativeMenu = new NativeMenu();
      men.addItem(new NativeMenuItem("test1", false));
      men.addItem(new NativeMenuItem("test2", false));
      var sub:NativeMenu = new NativeMenu();

      //men.addSubmenuAt(sub, 1, "subber"); // fail
      //men.addSubmenuAt(sub, 0, "subber"); // fail
      //men.addSubmenuAt(sub, men.numItems, "subber"); // good

      men.addSubmenu(sub, "subber");
      men.addItem(new NativeMenuItem("aftersub", false));

      //men.addSubmenu(sub, "subber"); // good

      this.bb.addEventListener(MouseEvent.CLICK, this.onbb);

      function setTrayMenu(mm:NativeMenu)
      if (NativeApplication.supportsSystemTrayIcon)
        if (NativeApplication.nativeApplication.icon.bitmaps.length)
         var sys:SystemTrayIcon = NativeApplication.nativeApplication.icon as SystemTrayIcon;
         if (sys != null)
          sys.menu = mm;

      function onbb(e:Event)
      sub.addItem(new NativeMenuItem("sub1", false));
      sub.addItem(new NativeMenuItem("sub2", false));