There are three menu-related classes.
Contextmenu class
Contextmenubuiltinitems class // Class related to the built-in menu of the system
Contextmenuitem class // Classes related to user-defined menus
If you are not careful, you will be confused by these classes. For example, learn how to create a component in flashcs3 and draw any image.
Drag the bar component to the stage and change the name to MC
Then copy the following Code To the first timeline of the main timeline:
VaR CM: contextmenu = new contextmenu (); // Define the CM object and assign it to the visual component. // The CM attribute is modified in the subsequent code. Achieve custom results // Then the built-in menu ● user menu will be modified separately MC. contextmenu = cm; // Of course, you can assign a value to the stage. The following statement // Contextmenu = cm; ////////// Edit the built-in menu //////////////////////// //////////////// Cm. hidebuiltinitems (); /* // You can also use the following method to selectively hide the built-in menu VaR CMB: contextmenubuiltinitems = new contextmenubuiltinitems (); CMB. Print = false; CMB. Quality = false; CMB. Zoom = false; CMB. Loop = false; Cm. builtinitems = CMB; // The builtinitems attribute is a contextmenubuiltinitems value, // You need to modify the contextmenubuiltinitems value and assign it to CM. builtinitems. // Attribute to modify the built-in menu. */ //////////////////////////////////////// //////////////////////////// ///////// edit the user menu ////////////////////// //// // var cm1: contextmenuitem = new contextmenuitem ("menu 1", false, true, true) var cm2: contextmenuitem = new contextmenuitem ("menu 2", false, true, true) var cm3: contextmenuitem = new contextmenuitem ("menu 3", false, false, true) CM. customitems. push (cm1); // Title name, split line, available, visible CM. customitems. push (cm 2); CM. customitems. push (cm3); ///////// note that the custom menu can be dynamically modified during running. Check that the individual has played the following: // /// // Listener event function /////////// ///////////// // Note that the object for listening is contextmenuitem, // Add listeners to the three contextmenuitem objects (cm1, cm2, cm3, and so on) in sequence. Cm1.addeventlistener (contextmenuevent. menu_item_select, clickmenu) Cm2.addeventlistener (contextmenuevent. menu_item_select, clickmenu) Cm3.addeventlistener (contextmenuevent. menu_item_select, clickmenu) Function clickmenu (E: contextmenuevent ){ Trace (E. Bubbles) // false, whether to bubble Trace (E. cancelable) // false, whether to cancel Trace (E. contextmenuowner) // [object movieclip], the object to which it belongs Trace (E. currenttarget) // [object contextmenuitem], Trace (E. mousetarget) // [object movieclip]. Right-click the object to display the List objects in the context menu. Trace(e.tar get) // [object contextmenuitem] Trace(e.tar get. Caption) // menu 1, which can be used to determine the number of subsequent operations or functions to be executed. Trace (E. currenttarget. Caption) // menu 1 } |
Very powerful and easy to learn