Tutorial: AS3 code for the custom right-click menu

0

The tutorial om how to create your own custom right-click menu for Adobe Captivate showed you how to do it with Actionscript 2.0.

The same can be achieved with Actionscript 3.0 so I thought I would post the code here. The AS3 code is very similar to the AS2 code so I will not explain it in detail. Take a look at the AS2 tutorial instead for a full explanation.

Full AS3 code for the custom right-click menu:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Create the menu variable
var myCustomMenu:ContextMenu = new ContextMenu();

// hide the standard menu items
myCustomMenu.hideBuiltInItems();

// create your custom menu items.
var menuItem1:ContextMenuItem = new ContextMenuItem(".: Developed by www.cpguru.com :.");
var menuItem2:ContextMenuItem = new ContextMenuItem("-> Click here to visit our webpage");

// set up a listener for menuItem2
menuItem2.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, openWebsite);

// push the custom menu items to the menu
myCustomMenu.customItems.push(menuItem1, menuItem2);
this.contextMenu = myCustomMenu;

// the function to open up your website
function openWebsite(e:ContextMenuEvent):void {
var url:String = "http://www.cpguru.com";
var request:URLRequest = new URLRequest(url);
navigateToURL(request, '_blank');
}
Share.

Comments are closed.