FLASH MX 2004 right button menu show

Source: Internet
Author: User
Tags control characters copy rewind
Menu | Right button

In the era of Flash MX, everyone would like to put a custom right-click menu in their work, now Flash upgraded to 2004, can finally put on their own right-click menu Show: P (this for the game writer-especially the RPG game writer, the hands are undoubtedly more sword)


In 2004, the main use of the ContextMenu class and the Contextmenuitem class to control the right-click menu. The ContextMenu object can be attached to a specific button (implemented using the Menu property of the button Class), a movie clip (implemented using the Menu property of the MovieClip Class), or a text field (implemented using the Menu property of the TextField Class). You can also attach to the entire movie level.

Flash player has three types of contextual menus: the standard menu (which appears when you right-click in Flash Player), the Edit menu (appears when you right-click on a selectable or editable text field), and the Error menu (appears when the SWF file fails to load into Flash player). Only standard menus and edit menus can be modified using the ContextMenu class. The custom menu item always appears at the top of the Flash Player context menu and is above all visible built-in menu items, separated by a separator bar between the built-in and custom menu items. A context menu contains no more than 15 custom menu items.


Well, no more, first let's take a look at the default right-click menu in Flash Player: only one frame in the home view (Figure 1)


In the case of multiple frames in the home view (Figure 2)

We can see that in multiple frames, more than single frames [play, loop], [back, fast-forward, return] are a total of 5 items in the two groups of submenu items.

(The following tutorials are based on the latter-for example, a multiple-frame source file in the main scene.)

In the right-click menu, we can see seven groups of 13 menu items, except "setting ..." and "about ..." cannot be hidden, and other menu groups can be hidden with AS.

★ Hide Right Click menu

Let's first include the following as code in the first frame of the main scene:


= = = Customize Right click menu ===aiyi2003 (2004.01.03)
MyMenu = new ContextMenu ();
Mymenu.hidebuiltinitems ();
_root.menu = MyMenu;
Custom Right Click menu * * * code END



This as code snippet has five elements, preceded by the "//" code is annotated, does not execute.
2nd line of code: MyMenu = new ContextMenu ()
Used to create a new ContextMenu object. That is, create your own right-click menu--"MyMenu".
Line 3rd code: Mymenu.hidebuiltinitems ()
Hidebuiltinitems () can hide all the built-in menu items (except settings and about) in the specified ContextMenu object.
Add this line of code, that is, "Zoom in," "Quality", "play", "Back", "print" and other menu items are hidden.
4th Line of code: _root.menu = MyMenu
Set the right-click menu in the main scene to the custom MyMenu menu above.

The output is a. swf file test (see Figure 3)


As we can see, in the right-click menu, other menu items are hidden except for the "settings" and "about" items that cannot be hidden.

★ Show Only one of the menu (see Figure 4)


For example, just want to display the "Quality" menu in the right-click menu, the "Zoom in", "Play" and other menu items to remove, we can add a line in the as statement above, into:

= = = Custom Right Key menu ===aiyi2003 (2004.01.03)
MyMenu = new ContextMenu ();
Mymenu.hidebuiltinitems ();
MyMenu.builtInItems.quality = True
_root.menu = MyMenu;
Custom Right Key Menu * * * code END

★ Delete Only one of the menu (see Figure 5)

For example, just to remove the Zoom menu group, we just add in frame 1th:

= = = Custom Right Key menu ===aiyi2003 (2004.01.03)
MyMenu = new ContextMenu ();
MyMenu.builtInItems.zoom = False
_root.menu = MyMenu;
Custom Right Key Menu * * * code END



(Figure 4 Example) we added a row: MyMenu.builtInItems.quality = True

(5) We used the MyMenu.builtInItems.zoom = False

Here, let's introduce Builtinitems.

Builtinitems objects with the following Boolean attributes: Zoom, quality, play, loop, rewind, Forward_back, and print. (the corresponding Chinese menu items are: Scaling, quality, playback, looping, rewind, fast-forward and return, printing) If you set these variables to False, the corresponding menu items in the specified ContextMenu object are deleted. These properties are enumerable and are set to True by default. So, friends can extrapolate, try to change (4) MyMenu.builtInItems.quality = true to MyMenu.builtInItems.play = True or change the MyMenu.builtInItems.zoom = False in (5) to MyMenu.builtInItems.forward_back = False, and test it yourself.

Well, read the above, you should be able to show and hide the Flash Player system with the right button menu items, but the light hidden display system with the menu is not interesting ah, if we want to put their own homemade right-click menu how to do? Answer--Look down:

To display your own defined content in the right-click menu, apply the Contextmenuitem class to complete it. Here is a detailed description of the use of the Contextmenuitem class.

★contextmenuitem class

Use the Contextmenuitem class to create a custom menu item that is displayed in the Flash Player context menu.

The custom menu item appears at the top of the right-click menu and is above the system default menu item. Custom menu items are always separated from the system default menu items by a separator bar. 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, and control characters, line breaks, and other white space characters are ignored. The length of all menu items must not exceed 100 characters. If a menu item is the same as any built-in menu item or other custom menu item, the menu item is ignored regardless of whether the matching menu item is visible. When you compare a menu item, the case, punctuation, and spaces are ignored.

The following words cannot appear in custom menu items: Macromedia, Flash Player, or settings.

☆ Test the custom Right key menu item

Add the following as to the 1th frame of the Flash MX 2004 New Document:

= = = Custom Right Key menu ===aiyi2003 (2004.01.03)
MyMenu = new ContextMenu ();
Mymenu.hidebuiltinitems ();
MyMenu.customItems.push (New Contextmenuitem ("Aiyi right-click Menu", test01));
function test01 (obj, item)
_root.menu = MyMenu;
Custom Right Key Menu * * * code END

We CTRL + RETURN Test (Figure 6)


New Contextmenuitem ("Aiyi right-click Menu", test01)

is used to define the text in the right-click menu ("Aiyi menu") and the function to perform when clicking on this menu item (test01)
When you add a new menu item, you first create a new Contextmenuitem object and then add it to the
Customitems Array. MyMenu.customItems.push (New Contextmenuitem ("Aiyi right-click Menu", test01));

function test01 (obj, item)

is used to customize the test01 function, which in function test01 (obj, item) {} can write itself as code to execute when this right-key menu item is pressed.


☆ Add the copyright information in the Custom right button menu

In my [FLASH MX 2004 Series Tutorial] in the SWF format demo effect, the right menu has "copyright information" and links and other custom menu items, now I would like to say [copyright information] of the production steps.

1, open the Flash MX 2004 Create a new document.
2, Ctrl+f8 a new MC (or in the [Insert] menu SELECT [New Symbol]), named "MC_ Copyright" (Figure A_1)


3, click "OK" to enter the "MC_ copyright" movie clips edited.
⑴ "Layer 1" to "background" and a rectangular tool to draw a rounded rectangle
⑵ new layer, named "Text", enter the copyright information at this level. (Figure a_2)


⑶ a new layer, named "Stealth button", the "background" layer of rounded rectangle copy a copy of this layer in situ paste. (Figure A_3)


⑷ Make sure the rectangle being pasted in place is selected, and press F8 to convert to a button. Named "Stealth button" (Figure A_4)


⑸ Double click on the "Stealth button" to enter its internal edit. First select frame 1th and then drag the keyframe in frame 1th to frame 4th (Figure A_5)


⑹ returns to the "MC_ copyright" movie clip. Select the Stealth button to press F9 to open the As Action panel and add the following as statement:

On (release)

4, return to the main scene, "Layer 1" renamed to "Copyright", ctrl+l open the library panel, "MC_ Copyright" to drag into the main scene. And aligns with the center of the main scene. In the property panel, name the instance name: "Copyright".

5, a new layer, named "as" in the as layer of the 1th frame add the following as code:
copyright._visible=0//Hide Copyright information
= = = Custom Right Key menu ===aiyi2003 (2004.01.03)
MyMenu = new ContextMenu ();
Mymenu.hidebuiltinitems ();
MyMenu.customItems.push (New Contextmenuitem ("Copyright Information", CR));
function CR (obj, item)
_root.menu = MyMenu;
Custom Right Key Menu * * * code END

6, CTRL + RETURN test.


In the test when we click the right mouse button, in the Pop-up right-click menu select "Copyright", will ' pop-up ' a copyright information, when we click on the copyright note, the copyright information will disappear. By adding a copyright note to the right-click menu, we can do it in this way, and the above method is simpler, and you can add your own imagination, but come out with a more beautiful "copyright message":

But the above method, there is a problem that does not count. Why is ' not a problem '? We can take a look at that when you open the copyright message by right-clicking the menu, do not click on the ' eject ' copyright on the mouse (that is, do not hide copyright information), click the right mouse button again, choose "Copyright information", there will be no response-that is of course, because the copyright information of the _visible value of 1, again set to 1 , of course it's not responding. This doesn't affect anything, but if you can get rid of it-easily remove such a small "BUG", of course it will be removed: P

To achieve this effect, just add two more lines as statements:

Join the function CR (obj, item) {} In the first frame of the home View "as" layer:
Mymenu.customitems[0].enabled = False
Then go to the MC_ Copyright movie clip, and add a statement to the "stealth button" in (release) {}:
_root.mymenu.customitems[0].enabled = true;

0 Here a brief introduction of the enabled attribute;

Enabled property, whether to enable or disable a Boolean value for the specified menu item. When the value is true, enable the specified menu item, or False to disable the specified menu item. By default, this property is true. You can specify menu items by Mymenu.customitems[0]. [0] After Mymenu.customitems[0] is the first menu item that you customize, the value is [1], the second menu item that you customize, and so on.

Flash source file Download [Click to download]



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.