4 Replies Latest reply on Apr 27, 2008 5:37 AM by TrAvIkK

    Right click emulation?

    TrAvIkK
      Hi!

      Is AS3 able to emulate right click of mouse, so I can get my own menu instead of flash player one ?
        • 1. Re: Right click emulation?
          JKohn99 Level 1
          You cannot get rid of all of the built in flashPlayer menu items but you can get rid of most of them and then add your own menu items

          // Step one - Get the default menu
          defaultMenu = Application.application.contextMenu;
          defaultMenu.hideBuiltInItems();

          // Now create the menu items to add to the menu.
          var item:ContextMenuItem = new ContextMenuItem("Some String");
          // Make sure you add an event listener to the menu item
          item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,handleStaticMenuItem);
          // Now add your item to the default menu or to your own menu
          defaultMenu.addMenuItem(item);

          Instead of using the defaultMenu you cam create your own menu
          and set it as the application menu:

          var myMenu = new ContextMenu();
          myMenu.hideBuiltInItems()
          // create items like above and add them to myMenu.
          //
          Application.application.contextMenu = myMenu;

          We use a singleton class that is used to manage different context menus in different parts of our application. The singleton creates a bunch of menus and depending on where the user is in the app, it enables the correct menu. Application code then registers event handlers with the singleton to respond to menu events.

          There is a training issue for end users so they know about the flash menu items that are built in.

          Hope this helps.

          • 2. Re: Right click emulation?
            justria Level 1
            Since the above code has a small error, here is a fixed version:

            quote:

            import mx.controls.Menu;

            public function initApp():void {

            var defaultMenu:ContextMenu;

            // Step one - Get the default menu
            defaultMenu = Application.application.contextMenu;
            defaultMenu.hideBuiltInItems();

            // Now create the menu items to add to the menu.
            var item:ContextMenuItem = new ContextMenuItem("Some String");
            // Make sure you add an event listener to the menu item
            item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,handleStaticMenuItem);

            // Now add your item to the default menu or to your own menu
            defaultMenu.customItems.push( item );
            }

            public function handleStaticMenuItem( anEvent:Event ):void {

            }
            • 3. Re: Right click emulation?
              TrAvIkK Level 1
              This doesn't really give me what i want... Thanks tho!
              • 4. Re: Right click emulation?
                TrAvIkK Level 1
                Hey!

                Is there any way to "cancel" the menu, that right click creates? Like pressing "ESC" after right click.
                If so, there would be a way to create own menu :)

                Maybe dispatching ESC key press would do the trick?