Thursday, June 7, 2007

Customizing Flash Context Menu

Flash context menu is the menu you see when you right click on any of the running Flash animations or applications.

I have customized it many times before but one of my friend asked me few days back that if he can remove the options from the Flash shortcut(context) menu so I thought of posting it on my blog for all of those trying to customize it.

I am pasting the code along with the explanation below -

var cMenu = new ContextMenu();

function dummy() {
trace("option clicked");
var cMenuItem1 = new ContextMenuItem("Option 1", dummy);
var cMenuItem2 = new ContextMenuItem("Option 2", dummy);
var cMenuItem3 = new ContextMenuItem("Option 3", dummy);
cMenu.customItems.push(cMenuItem1,cMenuItem2,cMenuItem3); = cMenu;

The ContextMenu class provides runtime control over the items in the Flash Player context menu, which appears when a user right-clicks on Flash Player.

First of all I have created an object of the class ContextMenu called "cMenu" & then called the built in function hideBuiltInItems() using the object which will hide the default options appearing on the right click.

The function dummy has been created to display a message in the output panel whenever user will click on the customized options added in the menu.

ContextMenuItem class is used to create objects for creating customized items, so for each option you want to put in the menu, you have to create an object. While creating object it takes two parameters, the caption & the function which will be executed on the click.

After doing this you have to push the items in the menu and to do that you use in built array associated with ContextMenu called ContextMenuItems.


So using the above code you push the items created into the menu & then your menu is ready to go after you change the current menu by putting in your menu name in the "menu" property using the following statement - = cMenu;

Enjoy Customizing Context Menu...

1 comment:

Anonymous said...

It is simply remarkable answer