In the flash mx era, we hope that you can add a custom right-click menu in your work. Now FLASH is upgraded to 2004, and you can finally put your own right-click menu to show off: P (this is undoubtedly more powerful for game writers, especially RPG game writers) in 2004, the ContextMenu class and the ContextMenuItem class are mainly used to control the right-click menu. The ContextMenu object can be appended to a specific Button (implemented using the menu attribute of the Button class) and video editing (implemented using the menu attribute of the MovieClip class) or a text field (implemented using the menu attribute of the TextField class), you can also attach it to the entire video level. Flash Player has three types of context menus: standard menus (displayed when right-clicking in Flash Player) and edit menus (displayed when right-clicking on selectable or editable text fields) and error menu (when the SWF file fails to be loaded to Flash Player ). Only standard menus and editing menus can be modified using the ContextMenu class. Custom menu items always appear at the top of the Flash Player context menu and are located above all visible built-in menu items. The built-in menu items and custom menu items are separated by a separator. A context menu cannot contain more than 15 custom menu items.
Well, let's not talk about it. First, let's take a look at the default right-click menu in Flash Player: when there is only one frame in the home scene (Figure 1) [upload = png] when uploadfile/20041322492413909.pn has multiple frames in the home scene (Figure 2) [upload = png] uploadfile/20041322493553097.pn, we can see that when there are multiple frames, there are five sub-menu items in the two groups: ["play", "loop"], ["back", "Fast Forward", and "return. (In the following tutorial, the source files with multiple frames in the main scenario are used as an example.) in the context menu, we can see 13 menu items in the seven groups, except for "setting... "and" about... you can use AS to hide other menu groups.★Hide right-click menuAdd the following AS code to the first frame of the main scenario:
// === Custom right-click menu === AIYI2003 (2004.01.03) myMenu = new ContextMenu (); myMenu. hideBuiltInItems (); _ root. menu = myMenu; // *** right-click the custom menu *** and the code ends.
This AS code segment contains a total of five lines. The code added with "//" is annotated and is not executed. 2nd line of code: myMenu = new ContextMenu () is used to create a new ContextMenu object. Create your own right-click menu-"myMenu ". 3rd line of code: myMenu. hideBuiltInItems () can hide all built-in menu items in the specified ContextMenu object (except for "settings" and "about ). Add this line of code to hide all menu items such as "zoom in", "quality", "play", "back", and "print. Line 1 code: _ root. menu = myMenu. Set the right-click menu in the home scene to the custom myMenu menu above.
The output is a .swf file test (see figure 3) [upload = png] uploadfile/200413225150000910.pn. We can see that in the right-click menu, except for the "Settings" and "about" items that cannot be hidden, other menu items are hidden.
★Show only one of the menus(See figure 4) for example, you only need to right-click the menu to display the option menu "quality" and remove the menu items such as "zoom in" and "play, we can add a row to the above AS statement to change:
// === Custom right-click menu === AIYI2003 (2004.01.03) myMenu = new ContextMenu (); myMenu. hideBuiltInItems (); myMenu. builtInItems. quality = true _ root. menu = myMenu; // *** right-click the custom menu *** and end the code [upload = png] uploadfile/2004132253545896.pn
★Delete only one menu(See figure 5) for example, if you only want to remove the "zoom" menu group, you only need to add: // === custom right-click menu === AIYI2003 (2004.01.03) to the 1st frame) myMenu = new ContextMenu (); myMenu. builtInItems. zoom = false _ root. menu = myMenu; // The *** custom right-click menu *** code ends.
[Upload = png] uploadfile/20041322534463427.pn
(Figure 4) We added a line: myMenu. builtInItems. we use myMenu in quality = true (5. builtInItems. zoom = false here we will introduce builtInItems objects with the following Boolean attributes: zoom, quality, play, loop, rewind, forward_back, and print. (The corresponding Chinese menu items are: Zoom, quality, play, loop, back, fast forward, return, and print.) if you set these variables to false, the corresponding menu items in the specified ContextMenu object are deleted. These attributes are enumerable and set to true by default. In this case, you can try to put the myMenu in (4. builtInItems. quality = true to myMenu. builtInItems. play = true or set myMenu in (5. builtInItems. zoom = false to myMenu. builtInItems. forward_back = false. Test it by yourself.
Well, after reading the above, we should be able to show and hide the right-click menu items that come with the Flash Player system, but it's boring to hide the menus that come with the system, what if we want to add our self-made right-click menu? Answer -- look down :)
To display the custom content in the right-click menu, use the ContextMenuItem class. The following describes how to use the ContextMenuItem class. [B]★ContextMenuItem class [/B]
You can use the ContextMenuItem class to create custom menu items displayed in the Flash Player context menu. The custom menu item appears at the top of the right-click menu and is located above the default menu item of the system. The custom menu items are always separated from the default menu items. You cannot add more than 15 custom menu items to the default menu in Flash Player. 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 the custom menu item: Macromedia, Flash Player, or settings.
☆Test custom right-click menu itemsAdd the following AS to the 2004 frame of the new flash mx 1st document: // === custom right-click menu === AIYI2003 (2004.01.03) myMenu = new ContextMenu (); myMenu. hideBuiltInItems (); myMenu. customItems. push (new ContextMenuItem ("AIYI right-click menu", test01); function test01 (obj, item) {trace ("test01");} _ root. menu = myMenu; // Click ** custom right-click menu ** to complete the code. Press Ctrl + enter to test the code (figure 6) [upload = png] uploadfile/20041322544463082.pn new ContextMenuItem ("right-click menu of AIYI", test01) is used to define the text in the right-click menu ("right-click of AIYI Menu ") and when you click the function (test01) to add a new menu item, you must first create a new ContextMenuItem object and then add it to the customItems array. MyMenu. customItems. push (new ContextMenuItem ("right-click menu of AIYI", test01 ));
Function test01 (obj, item) {trace ("test01");} is used to customize the test01 function, in function test01 (obj, item) you can write the AS code to be executed when the right-click menu item is pressed.
☆Add copyright information to the custom right-click menuIn my [flash mx 2004 series tutorials], the swf format shows the effect. Right-click the menu and choose custom menu items such as "copyright information" and "Friendship Link, now let's take a look at how to create [copyright information. 1. Open flash mx 2004 to create a new document. 2. Press Ctrl + F8 to create a MC (or select [new component] from the [insert] menu) and name it "MC _ Copyright" (figure A_1) [upload = png] uploadfile/20041322561719288.pn 3. Click "OK" to edit the "MC _ copyright" video clip. (1) rename "Layer 1" to "background" and draw a rounded rectangle using a rectangle tool (2) create a new layer, name it "text", and enter copyright information on this layer. (Figure A_2) [upload = png] uploadfile/2004132257125567.pn (3) Create a new layer, name it "invisible button", and Copy the rounded rectangle of the "background" layer, paste in-situ at this layer. (Figure A_3) [upload = png] uploadfile/20041322574253637.pn (4) ensure that the rectangle to be pasted in the original position is selected, and press F8 to convert it to a button. Name it "invisible button" (figure A_4) [upload = png] uploadfile/2004132251_6584.pn
⑸ Double-click "" to go to its internal editing. Select 1st frames, and then drag the key frames in 1st frames to 4th frames (figure A_5) [upload = png] uploadfile/2004132301079905.pn
The "MC _ copyright" video clip is returned. Select the "invisible button" and press the F9 key to open the AS action panel and add the following AS statement: on (release) {this. _ visible = 0} 4. Return to the main scenario, rename "Layer 1" to "copyright", Ctrl + L open the library panel, drag "MC _ copyright" to the home scene. And align with the center of the main scenario. In the property panel, name its "instance name" as "copyright ". 5. Create a new layer named "AS" and add the following AS code to the 1st frame of the AS layer: copyright. _ visible = 0 // hide copyright information //=== custom right-click menu === AIYI2003 (2004.01.03) myMenu = new ContextMenu (); myMenu. hideBuiltInItems (); myMenu. customItems. push (new ContextMenuItem ("copyright information", CR); function CR (obj, item) {copyright. _ visible = 1} _ root. menu = myMenu; // Click ** custom right-click menu ** to end Code 6. Press Ctrl + enter to test.
During the test, right-click and select "copyright information" from the shortcut menu. A description of the copyright information is displayed, when we click on the copyright notice, the copyright information will disappear. Right-click the menu and add the copyright notice. We can use this method to implement it. The above method is relatively simple and you can add your imagination, but a more beautiful "copyright information" is displayed :)
However, the above method is not a problem. Why is it 'not a problem? Let's take a look at it. When you open the copyright information by right-clicking the menu, you can right-click it again without hiding the copyright information, if you select "copyright information", there will be no response-that is, of course, because the value of _ visible of the copyright information is 1, and it is set to 1 again, of course, no response. This does not affect anything, but if it can be removed-it is easy to remove such a small "BUG", of course, it should be removed: P to achieve this effect, you only need to add two lines of AS statements: Add: myMenu to function CR (obj, item) {} in the first frame of the "AS" layer of the main scenario. customItems [0]. enabled = false. Then, go to the "MC _ copyright" video clip and add a statement on (release) {} to the "invisible" button. myMenu. customItems [0]. enabled = true;
○ Here, we will briefly introduce the enabled attribute and enabled attribute to enable or disable the boolean value of a specified menu item. If the value is true, the specified menu item is enabled. If the value is false, the specified menu item is disabled. By default, this attribute is true. You can use myMenu. customItems [0] to specify menu items. MyMenu. [0] after customItems [0] is the first menu item you have defined. When the value is [1], it is the second menu item you have defined.
FLASH source file download