Right Click Context Menu In Flash Movie Simple Method

This Tutorial Has Been Viewed 853 Times.


Customize right click menu in flash in a simple way.

We will start off by creating an instance of the ContextMenu class and then hiding the default items in it on the main timeline. Our context menu instance will be called myMenu_cm.

var myMenu_cm:ContextMenu = new ContextMenu();
myMenu_cm.hideBuiltInItems();
_root.menu = myMenu_cm;
1- Strict Data Typing was used to explicitly set the data type for myMenu_cm to ContextMenu.
2- The _cm suffix at the end of the variable name to activate ActionScript code hints for the ContextMenu class. 

The code is pretty basic, we created a new variable to store our instance of the context menu, we then used the .hideBuiltInItems method to remove all the defaults items from the menu and assigned this instance to the _root (main) timeline of the Flash movie. It is essential to note that the itemsAbout and Settings cannot be removed from the menu, some additional commands for debugging cannot be removed either while testing in the Flash authoring tool. You can test the code above in an empty movie to get a context menu similar to the one below.

Blank Context Menu

We used above the quick method for removing the default items from the context menu, it is possible to manually remove the items one by one in case you wish to retain some of these items for some reason or another. Here is how to do it.

var myMenu_cm:ContextMenu = new ContextMenu ();
myMenu_cm.builtInItems.zoom = false;
myMenu_cm.builtInItems.quality = false;
myMenu_cm.builtInItems.print = false;
myMenu_cm.builtInItems.save = false;
myMenu_cm.builtInItems.loop = false;
myMenu_cm.builtInItems.rewind = false;
myMenu_cm.builtInItems.forward_back = false;
_root.menu = myMenu_cm;

Adding Custom Menu Items

It is possible to add an unlimited number of items to do whatever action you desire. In order to do this you will have to first create an instance of theContextMenuItem and then apply a caption and a function to this element before adding this to the list of custom items. Here is an example:

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

var newItem1_cmi = new ContextMenuItem (“Contact Us”, contactPage); 
function contactPage (){
trace(“This is Mistonline.in”) 

myMenu_cm.customItems.push(newItem1_cmi);

_root.menu = myMenu_cm;

We started off by creating the variable newItem1_cmi to hold our instance of the contextMenuItem class. We named our new item Contact Us and assigned the function contactPage to the item. This means that whenever our new item is selected the function contactPage is called. We declared our functions afterwards, in this example we made our function do a simple trace command to show up the text given above. This is merely an example and you can in practice make your function do anything you want.

Our menu item was ready by then and all we had to do is add it to our menu, each menu has an array property for custom items. We used the array method .push to add our custom item to the menu, we then applied the new menu to the root level to do the trick. You can test the movie to see the new item placed in the context menu.

Context menu with one custom item

Thanks a lot republicofcode.com

VN:F [1.9.13_1145]
Rating: 7.0/10 (1 vote cast)
VN:F [1.9.13_1145]
Rating: 0 (from 0 votes)

Right Click Context Menu In Flash Movie Simple Method, 7.0 out of 10 based on 1 rating

Incoming search terms:





You will also be interested in ,

Tags: ,

One Response

  1. lincoln says:

    love your work big time and thumbz up!!!!

    VA:F [1.9.13_1145]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.13_1145]
    Rating: 0 (from 0 votes)

Leave a Reply

Spam protection by WP Captcha-Free

Proudly designed by Mistonline.in.
Affordable Seo PackagesSeo BlogEdu Backlinks
More in Flash, scripts (70 of 85 articles)