The previous as2.0 writing method is shared with you.
The code is as follows: |
Copy code |
Function gotoinlookme (){ GetURL ('http: // hi.baidu.com/inlookme', '_ blank '); } Var mymenu: ContextMenu = new ContextMenu (); // you need to add the ContextMenu type to the defined mymenu, or no code prompt will appear later. Mymenu. hideBuiltInItems (); // hide the default menu, but "settings" and "about" cannot be hidden. // New ContextMenuItem (caption, callbackFunction, [separatorBefore, [enabled, [visible]) complete function prototype Mymenu. customItems. push (new ContextMenuItem ("design support-inlookme", gotoinlookme); // add the defined entries to the menu _ Root. menu = mymenu; // bind to the home scene. You can also bind a menu to a button or other component. |
For more information about how to use as3.0, see here.
The code is as follows: |
Copy code |
Package { Import flash. display. Sprite; Import flash. events. Event; Import flash. ui. ContextMenu; Import flash. ui. ContextMenuItem; /** * Hide the Flash context menu instance * @ Author fising <fising@qq.com> */ Public class Main extends Sprite { Public function Main (): void { If (stage) init (); Else addEventListener (Event. ADDED_TO_STAGE, init ); } Private function init (e: Event = null): void { RemoveEventListener (Event. ADDED_TO_STAGE, init ); // Stage. Showdefaconcontextmenu = false; Var cmitem: ContextMenuItem = new ContextMenuItem ('Madhouse Inc. Ver 100', true ); Var cm: ContextMenu = new ContextMenu (); Cm. hideBuiltInItems (); Cm. customItems. push (cmitem ); This. contextMenu = cm; } } } |
Note:
The custom menu item appears at the top of the context menu and is located above all built-in menu items. Custom menu items and built-in menu items are always separated by separators. You cannot add more than 15 custom menu items to the context menu. Each menu item must contain at least one visible character. Control characters, line breaks, and other blank characters are ignored. The length of all menu items cannot exceed 100 characters. If a menu item is the same as any built-in menu item or other custom menu items, this menu item is ignored no matter whether the matching menu item is visible or not. When comparing menu items, uppercase and lowercase letters, punctuation marks, and spaces are ignored. The following words cannot appear in custom menu items: Macromedia, Flash Player, and settings.