How to Customize Right Click Menu in Flash

POSTED IN Tutorials

Do you want to protect your flash with a copyright text or to include a link to your website in Adobe Right Click Menu?
In this tutorial I’ll show you the steps to create a Custom Right Click Menu.

Code for AS2:

function rightclickMenu(){}
function clickMenu2(){
    getURL("http://www.template-tuners.com", _blank);
}
function clickMenu3(){
    getURL("http://www.template-tuners.com/iblog/", _blank);
}

MENU = new ContextMenu();
MENU.hideBuiltInItems();

Functioned = new ContextMenuItem("© Template Tuners 2010", clickMenu);
Functioned2 = new ContextMenuItem("Tutorial By Template Tuners", clickMenu2);
Functioned3 = new ContextMenuItem("Template Tuners Blog", clickMenu3);

MENU.customItems.push(Functioned);
MENU.customItems.push(Functioned2);
MENU.customItems.push(Functioned3);

_root.menu = MENU;

Code for AS3:
AS3: – org > addons > CustomMenu.as

package org.addons{
    import flash.display.*;
    import flash.events.*;
    import flash.net.*;
    import flash.ui.*;

    dynamic public class CustomMenu extends Sprite{;
        public static var menuItem2:ContextMenuItem=new ContextMenuItem("Go Fullscreen");
        public static var menuItem3:ContextMenuItem=new ContextMenuItem("Exit Fullscreen");
        public static var cm:ContextMenu=new ContextMenu;
        public static var year:Date=new Date;
        public static var menuItem1:ContextMenuItem=new ContextMenuItem(year.getFullYear() + "Template Tuners");

        public function CustomMenu() {
            // la la la
        }

        public static function goToMainSite(param1:ContextMenuEvent):void {
            var _loc_2:URLRequest;
            _loc_2=new URLRequest("http://www.template-tuners.com");
            navigateToURL(_loc_2,"_blank");
        }

        public static function buildMenu(stage:Object):CustomMenu {
            var _loc_2:CustomMenu;
            _loc_2=new CustomMenu ;
            Global.data._game.addChild(_loc_2);
            trace("RIGHT CLICK MENU ENABLED");
            menuItem3.separatorBefore=true;
            menuItem3.enabled=false;
            menuItem1.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,goToMainSite);
            menuItem2.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,goFullScreen);
            menuItem3.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,exitFullScreen);
            cm.hideBuiltInItems();
            cm.customItems.push(menuItem1,menuItem2,menuItem3);
            Global.data._game.contextMenu=cm;
            return _loc_2;
        }

        public static function goFullScreen(param1:ContextMenuEvent):void {
            Global.data._game.displayState=StageDisplayState.FULL_SCREEN;
            menuItem2.enabled=false;
            menuItem3.enabled=true;
            return;
        }

        public static function exitFullScreen(param1:ContextMenuEvent):void {
            Global.data._game.displayState=StageDisplayState.NORMAL;
            menuItem2.enabled=true;
            menuItem3.enabled=false;
            return;
        }
    }
}

One Response to “How to Customize Right Click Menu in Flash”

  1. Creating an app to allow users to input information in a field and have it appear inside an HTML doc.?…

    I found your entry interesting do I’ve added a Trackback to it on my weblog :)

  2. Der Splog! on 10 July, 2010 at 7:33 am

Leave a Reply

Go to Top