Your Ad Here

December 25, 2009

Customizing Context Menu in Flash

Name: Context Menu
Category: Intermediate

In Macromedia Flash you can add and edit the standard Context Menu (Right Click Menu). This tutorial will teach you how to customize the context menu by removing default items and adding your own items to the menu.

1- Open Macromedia Flash and create a new document.

2- Select first frame of the first layer (empty by default).

3- Open up the Actions Panel and write the actions as follows:

custom_menu = new ContextMenu();
custom_menu.hideBuiltInItems();
menu1 = new ContextMenuItem("!Learn to Flash!", doNothing, false, false, true);
menu2 = new ContextMenuItem("Goto my Web Page", gotoSite, false, true, true);
menu3 = new ContextMenuItem("Copyright© All Rights Reserved", doNothing, false, false, true);
custom_menu.customItems.push(menu1);
custom_menu.customItems.push(menu2);
custom_menu.customItems.push(menu3);
_root.menu = custom_menu;
function doNothing() {
}
function gotoSite() {
getURL(http://learntoflash.blogspot.com/);
}

4- Explanation:


>>custom_menu = new ContextMenu();
    custom_menu.hideBuiltInItems();

These will create a new menu instead of the default menu and will hide the built in items in it. But the the three items shown in image below cannot be removed by any script.







>>menu1 = new ContextMenuItem("!Learn to Flash!", doNothing, false, false, true);

    menu3 = new ContextMenuItem("Copyright© All Rights Reserved", doNothing, false, false, true);

This will create two Context Menu items which will be unclickable because “doNothing” function is called in them. Read further to understand better.


>>menu2 = new ContextMenuItem("Goto my Web Page", gotoSite, false, true, true);


This will create another Context Menu item, which will be clickable as “gotoSite” function is called here.


>>function doNothing() {

    }

This will create an empty function. That’s why when this function is called in the two menus they became unclick able. As named this function will do nothing.

>>function gotoSite() {
    getURL(http://learntoflash.blogspot.com/);
    }

This will create a function which is reflecting to a web site, as getURL function is called in it. When the menu item with this function will be clicked it will direct to the website written in the function.


5- All done, now test the movie clip by pressing Ctrl+Enter.

No comments:

Post a Comment

Please use sensible language.....!