It’s typical, that every time i wanted to add a custom right click menu to my flash apps, i just googled for it and pasted in the usual code. It just occurred to me that these 5-10 lines of independent code don’t have to (and shouldn’t) be part of the main code of my projects. After all, i always want the same thing in my menus: the name of the project and a link to my homepage. So, to keep my code at a minimum, i converted that context menu into a nice little class. Now, every time i want to add it, all i have to write is:
import com.locus_delicti.utils.LocusMenu;
contextMenu = LocusMenu.buildMenu("kuler Patterns Gadget");
where the String “kuler Patterns Gadget” is the name of my project.

locus context menu
The menu class takes that string, takes the year i’m publishing it, and automatically creates the menu. The class code follows.
LocusMenu.as
package com.locus_delicti.utils
{
import flash.ui.ContextMenu;
import flash.ui.ContextMenuItem;
import flash.events.ContextMenuEvent;
import flash.net.URLRequest;
import flash.net.navigateToURL;
public class LocusMenu
{
public static function buildMenu(title:String):ContextMenu{
var d:Date = new Date();
var cm:ContextMenu = new ContextMenu();
cm.hideBuiltInItems();
var info1:ContextMenuItem = new ContextMenuItem(title);
info1.enabled = false;
cm.customItems.push(info1);
var info2:ContextMenuItem = new ContextMenuItem("© "+d.getFullYear()+" locus-delicti.com");
info2.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, linkHandler);
cm.customItems.push(info2);
return cm;
}
private static function linkHandler(e:ContextMenuEvent):void{
navigateToURL(new URLRequest("http://www.locus-delicti.com"), "_blank");
}
}
}