Flash's right-click menu

xiaoxiao2021-03-19  196

MX 2004 ~~ AS2.0 has this feature

First look at an example:

var my_cm = new ContextMenu (); my_cm.hideBuiltInItems (); my_cm.customItems.push (new ContextMenuItem ( "Sucy", func_1)); my_cm.customItems.push (new ContextMenuItem ( "Alien", func_2)); my_cm. CustomItems.push (New ContextMenuItem ("JINNI", FUNC_3); my_cm.customItems.Sort (); function func_1 () {trace ("called sucy!")} function func_2 () {trace ("Called Alien!") } Function func_3 () {trace ("Called Jinni!")} _root.Menu = MY_CM;

Test, click the right mouse button, what did you see? Haha, click Alien, Jinni or Sucy to call FUNC_1, FUNC_2, and FUNC_3.

In fact, the steps to add the right-click menu are simple: 1. Create a ContextMenu menu object. 2. Create a ContextMenuItem menu item and add it to the ContextMenu object. 3. Customize the process function for each menu item. 4. Apply menu objects to MC, Button, or TextField.

Method is: moists / button / textfield instancename.Menu = contextMenu Instacename;

For example, my_btn.Menu = my_cm;

Looking back at this example of the code, you know how much you know about the core part of the right mash menu, they are:

a) New contextmenu (); create a ContextMenu object. Simply put, it is a container that is used to print the user-defined menu item. In addition to simple creation in this example, you can also add an event while you created, this event will happen when the user clicks the right button.

example:

Var my_cm = new contextMenu (RightClick); Function rightClick () {("Right Clicked!")} _root.Menu = MY_CM;

Click the right mouse button, output "Right Clicked!"; In fact, you already know how to use the right-click event, unfortunately, no matter how, the menu will pop up, so if you want to use the right-click effect It will still be very unhappy. ()

b) ContextMenu.hidebuiltinitems (); method for ContextMenu objects.

The function can be seen from the name, hide the built-in menu item, such as COPY, ZOOM IN, etc., of course, settings and copyright information will not be hidden. In addition, you have to pay attention to that custom menu items cannot serve as Copy, Zoom IN, otherwise they will not work.

c) The properties of the ContextMenu.cutstomItems ContextMenu object.

It is an array that stores all user-defined menu items because the menu item itself is an object, so every element of this array is an object. What is even better, you can use the an array to operate him, which is certain for you. You can use the Push () method to add menu items to the item menu, and access it in the way in the CUTSTOMITEMS [i]. And other arrays you can also make good use:, for example, in this example, you can add menu items to CutStomItems, using the sort () method.

The final menu is arranged in alternatives. In addition, you can also change the content of the menu item through the array operation.

d) New ContextMenuItem (CAPTION, FUNC) Creates a contextMenuItem object. Caption: The name of the menu item (note that it is mentioned, don't work with the built menu). CAPTION is also the properties of ContextMenuItem, the meaning of meaning. FUNC: The name of the process function after the menu item is clicked. Several properties of several contextMenuItem objects can also be passed as parameters when creating objects.

(1) Enabled: The menu item is available. (Unavailable as gray) defaults to true. (2) SeparatorBefore: Subvalues ​​(used for menu classification) are displayed below. The default is false. (3) Visible: The menu item is visible. The default is True.

The complete constructor is: New ContextMenuItem (Caption, Func, SeparatorBefore, Enabled, Visible), Example:

MY_MC = New ContextMenuItem ("Item", Func_Item, True, False, True;

This method creates a menu item named Item, which will appear on it, which is visible, but in an unavailable state, the process function is func_item ().

About creating a right-click menu The most basic thing you have already mastered, let's take some extra things. E) method of contextMenuItem.copy () ContextMenuItem object.

Returns a copy of a menu item object, and the return value is still a ContextMenuItem object.

f) Events of the ContextMenuItem.onSelect ContextMenuItem object. When the menu item is selected. The process of processing the event is actually a FUNC that is created when creating an object. However, if you create an object, the FUNC will not take effect on the Onset event after the object is created.

g) ContextMenu.copy () ContextMenu object method, return a copy of the ContextMenu object. The return value is still the ContextMenu object.

h) ContextMenu.Onselect ContextMenu object events. In the user calling the menu, and the menu occurs before. It allows you to create a menu based on the position where the mouse is located. The process of the event can have two parameters:

MY_CM.ONSELECT = Function (item: object, item_menu: contextmenu)

Item: When the user clicks on the mouse, the object instance below the mouse pointer can be the MovieClip, buttons, text domain.

This allows you to achieve the effect similar to the right-click menu of the operating system, that is, click the right click on the different objects to appear different menus.

You can use InstanceOf to determine the type of object referred to in the mouse pointer.

Item_Menu: The menu item object corresponding to the current menu. Example: (This is an example in help) my_cm = new contextmenu (); menuhandler = function (obj: object, menu: contextMenu) {if (Obj InstanceOf MovieClip) {Trace ("Movie CLIP:" Obj);} (Obj InstanceOf Textfield) {Trace ("Text Field:" Obj);}}}}}} my_cm.onness = menuhandler;

_Root.Menu = MY_CM;

You can build a few MC, Button and TextField in the scene, and click on the right mouse button in these locations to see what is different.

g) The properties of the ContextMenu.BuiltinItems ContextMenu object.

It itself is an object that contains the following Boolean properties, respectively corresponds to the built-in menu item of Flash Player:

Save, Zoom, Quality, Play, Loop, Rew, Forward_Back, Print.

Set the appropriate properties to remove it from the menu item.

example:

MY_CM = new contextmenu (); my_cm.bulidinitems.zoom = false; _root.Menu = my_cm;

Test, after clicking the right button, the zoom in / zoom out option will not appear in the menu. If you want to shield all the built-in menu items, use contextMenu.hidebuiltinitems ().

转载请注明原文地址:https://www.9cbs.com/read-130105.html

New Post(0)