Skip to navigation

malevolent design weblog

This blog is now defunct, but you can find more stuff over at my personal site

Using The Flash Right-Click Menu For Version And Credits

If you’re making a Flash game (rather than a serious application), it might not occur to you to make use of the right-click context menu, but it’s handy for:

  • Knowing exactly which version of the game you’re currently playing
  • Claiming credit for your work

Here’s a simple ActionScript 3 code example. Firstly, you might have some kind of configuration object in your game, in which you can easily adjust things like the version number:

var config:Object =
{
  title:'An Amazing Game',
  version:'1.0',
  creditTitle:'malevolent design',
  creditURL:'http://malevolent.com/'
};

Then you just need to create a new ContextMenu, populate it with items, and replace the default menu:

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

var customContext1:ContextMenuItem = new ContextMenuItem(config.title+' v'+config.version);
customContext1.enabled = false;
customContext.customItems.push(customContext1);

var customContext2:ContextMenuItem = new ContextMenuItem('Created by:', true);
customContext2.enabled = false;
customContext.customItems.push(customContext2);

var customContext3:ContextMenuItem = new ContextMenuItem(config.creditTitle);
customContext3.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, function(e:ContextMenuEvent):void { navigateToURL(new URLRequest(config.creditURL), '_blank'); });
customContext.customItems.push(customContext3);

contextMenu = customContext;

The above code would give you:

Flash right-click context menu example

Oh, and if you’re creating a fiendish puzzle game, the context menu might be a good place to hide a clue…


Comments


Comments are now closed for this entry.