Home » Programming » ActionScript » Custom ContextMenu in Flash

Custom ContextMenu in Flash

Custom ContextMenu in Flash

As you know, the Flash Player includes a control system associated with a right-click menu to enlarge and frame control and access to the player, this allows ActionScript code can be changed by a special building.

If you want your own Context Menu in your project, or even in some parts of the tools to use it. And related information, such as your email or contact number in the right click menu of your project.
By the ContextMenu property of the flash can easily do this, in this article we describe in detail in this case.

The final sample was checked before starting the project. Right-click on the logo on the screen and right-click menus for the function to look at.

 

برای مشاهده نیاز به فلش پلیر دارید

In this article we consider the following cases:

  1. hide right click menu default items.
  2. add item to right click menu.
  3. active function to menu items.
  4. add custom menu to an symbol.

Hide right click menu default items

To hide the default items in right click menu arrow should use the ContextMenu class.
As usual, you must define the class and pay a variable rate that can change its properties, and use it. This is a step by step look into the issue.

To start a new project we create Flash ActionScript 3. Then we define a variable called my_menu contextMenu type:

var my_menu:ContextMenu = new ContextMenu();
To hide all context menu items can use the method hideBuiltInItems () is used, as is clear from the code of this method is that there is no argument:
var my_menu:ContextMenu = new ContextMenu();
my_menu.hideBuiltInItems();
However, to make these changes should be implemented in the flash menu on your definition (my_menu) corresponding to the flash contextMenu than that.
Note If you start contextMenu do not write or write this refers to the original object, the more we discuss about the properties of the object:
var my_menu:ContextMenu = new ContextMenu();
my_menu.hideBuiltInItems();
contextMenu = my_menu;
If test the project, you will notice that the default menu to zoom in and control over the frame and the other could not be displayed.
However, we must note that the menus can not be removed normally About and Setting the right-click menu.
Also relevant to your Flash Debugger which is also one of the issues that can not removed it.

contextmenu_iflashlord_6

This method is a quick and easy way to do it, but you can hide them manually.
Maybe your project need not be removed and remain some cases it may be better to hide the offers you full access. You should builtInItems object and its relevant elements of a boolean value, false to hide and show true, of course, by default, all of these things are true.

var my_menu:ContextMenu = new ContextMenu();
my_menu.builtInItems.forwardAndBack = false;
my_menu.builtInItems.loop = false;
my_menu.builtInItems.play = false;
my_menu.builtInItems.print = false;
my_menu.builtInItems.quality = false;
my_menu.builtInItems.rewind = false;
my_menu.builtInItems.save = false;
my_menu.builtInItems.zoom = false;
contextMenu = my_menu;

This code is similar to the previous result will be.

contextmenu_iflashlord_6

Add item to right click menu

In addition we have the right-click menu to delete items, ability to add new items as well.To do this you must use the ContextMenuItem class.
And it customItems object respective to a ContextMenu object in this example (my_menu) is added. The work done by the push method.

ContextMenuItem have four arguments input, in this example we just display the text that is entered into our first argument, arguments in order to display the context menu entry text (String), insert a line before the menu item (Boolean), enabled or disabled (Boolean), show or hide (Boolean) is. Of course, this arguments of the amount directly to the respective object is also initialized.
In the following section, we noted that:

var my_menu:ContextMenu = new ContextMenu();
my_menu.hideBuiltInItems();

var my_notice = new ContextMenuItem("IFLashLord.com");
my_menu.customItems.push(my_notice);

contextMenu = my_menu;

By testing the above code by right-clicking on it you will see the result.

contextmenu_iflashlord_1

You have the option to add multiple items to the right click, then we have two other items are added to the project, Note that the object name should be related to other items and put them in push method below, separated by commas:

var my_menu:ContextMenu = new ContextMenu();
my_menu.hideBuiltInItems();

var my_notice = new ContextMenuItem("IFLashLord.com");
var my_email = new ContextMenuItem("me@iflashlord.com");
var my_copyright = new ContextMenuItem("Copyright © 2014");

my_menu.customItems.push(my_notice, my_email, my_copyright);
contextMenu = my_menu;

The result of the code above is adding new items to the context menu.

contextmenu_iflashlord_3These properties can be adjusted for ContextMenuItem class, these characteristics are the same as those of the class is actually argument.

  1. caption – string text to show.
  2. enabled – active click on item.
  3. separatorBefore – add separator line before item.
  4. visible – show or hide item.

These properties can be used directly and change, in this section, we will disable your copyright text and a separator line before it is put:

var my_menu:ContextMenu = new ContextMenu();
my_menu.hideBuiltInItems();

var my_notice = new ContextMenuItem("IFLashLord.com");
var my_email = new ContextMenuItem("blue_chi@roc.com");
var my_copyright = new ContextMenuItem("Copyright - 2009");

my_copyright.enabled = false;
my_copyright.separatorBefore = true;

my_menu.customItems.push(my_notice, my_email, my_copyright);
contextMenu = my_menu;

The sample you see that related option is disabled and click on it there is no other possibility and that a line has to be separated before it is placed.

contextmenu_iflashlord_4At this stage you can add new items to the context menu continue to apply to the items described above for example, clicking on an item you want to open your website.
Or arrows move you to another party or else this will be possible by defining event for the item.

Active function to menu items

Click on an item to perform a function, we need to define an event and as usual it did do addEventListener method, to get the selected item from ContextMenuEvent and MENU_ITEM_SELECT event as the event you are using and this event to your ContextMenuItem object (in this example my_notice) assigned.

In this case, click on the first item (IFLashLord.com) openLink you run the function, according to the code you’ve put into this function opens a link to the website:

var my_menu:ContextMenu = new ContextMenu();
my_menu.hideBuiltInItems();

var my_notice = new ContextMenuItem("IFLashLord.com");
var my_email = new ContextMenuItem("me@iflashlord.com");
var my_copyright = new ContextMenuItem("Copyright © 2014");

my_copyright.enabled = false;
my_copyright.separatorBefore = true;

function openLink(e:ContextMenuEvent):void{
    navigateToURL(new URLRequest("http://www.iflashlord.com"));
}
my_notice.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, openLink);

my_menu.customItems.push(my_notice, my_email, my_copyright);

contextMenu = my_menu;

Add custom menu to an symbol

As a special feature of the flash menu there are distinctly different menu object in Flash as well.
In this example, we’ve created a MovieClip object and now for the instance name or a name defined to have access to it in ActionScript, in this example, the name of the object you’ve logo_mc.

All such examples of previous work, only the last stage of the menu is defined as the ratio would have contextMenu.
ContextMenu had the desired object (logo_mc) assigned:

var my_logo_menu:ContextMenu = new ContextMenu();
my_logo_menu.hideBuiltInItems();

var my_logo_notice = new ContextMenuItem("I am Behrouz");

my_logo_menu.customItems.push(my_logo_notice);

logo_mc.contextMenu = my_logo_menu;

The test example see separate menu for the right click the logo and the logo on the outside of the previously defined menu to be displayed.

contextmenu_iflashlord_2
Like the ones you already have all the permissions related items, for example, in this section we will disable an item of this object:

var my_logo_menu:ContextMenu = new ContextMenu();
my_logo_menu.hideBuiltInItems();

var my_logo_notice = new ContextMenuItem("I am Behrouz");
my_logo_notice.enabled = false;

my_logo_menu.customItems.push(my_logo_notice);

logo_mc.contextMenu = my_logo_menu;

contextmenu_iflashlord_5You can use this feature in various projects, more dynamic and more useful to your Flash projects.

Be successful.

Print Friendly
Tags :
Previous post link
Next post link

About Behrouz Pooladrag

Born: May 27, 1988 Occupation: Adobe Flash, programming and web design, graphic design, multimedia, web-based software

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Scroll To Top