Controlling the Context Menu (All Versions 5 and higher)
Ever see right-click (context) menus for Flash? They contain things like "Play" and "Rewind" and a whole bunch of other crap. Game design, Secret Codes for the Super Secret Chess Club Flash Site and others would be DOOMED! If not for the alteration of the Context Menu. It's a fairly simple process, so let's get rid of the boring same old same old and make a context menu people can use!
First we are going to open the functions and declare 2 things right away. First a non-clickable entry, and a getURL entry. This way we can make the menu have things that people can NOT click on, and items that take them to sites or pages we want them to go to. I have named mine noCLick and getMySite. You can name yours whatever you want.
Code:
/**** My Context Menu*****/
function noClick() {
}
function getMySite() {
getURL("http://frozencoyotelabs.com/", "_blank");
}
Great! So we have functions and they don't do a damn thing! Well, first let's tell Flash to turn off that old nasty context menu and start using ours!
Code:
var myMenu:ContextMenu = new ContextMenu();
myMenu.hideBuiltInItems();
Great, we turned off the old one by declaring a new one named "myMenu" (original I know) And we have made it blank, by turning off the built in items that come with a standard Flash CM. (that's Context Menu for you non-abbreviaters)
*note, there are items in the CM you will NEVER be allowed to remove. I know. It sucks. Deal with it. Just for your information, those items (In Flash Player 9 and higher) are: Settings, and About Adobe. In Player 10 they added "Show redraw regions" as well. Suck it up.
Next we need to declare some new menu items. Let's add a copyright with date, and a warning:
Code:
var copyrightNotice:ContextMenuItem = new ContextMenuItem("© 2005 - 2008 FrozenCoyote Labs", noClick);
var copyProtect:ContextMenuItem = new ContextMenuItem("No reproduction without permission of FCL", noClick);
Here I have a new variable (each it's own name, copyrightNotice for one and copyProtect for the other. We tell Flash these variables are a new CM item then we define them. first up, what it says in the menu itself. then, the function it will carry over. AS you can see, both are using the noClick function. It means they are there and they are to be seen, not clicked.
So lets add some more cool things, a line separator and something to click on:
Code:
copyrightNotice.separatorBefore = true;
var mySiteLink:ContextMenuItem = new ContextMenuItem("FrozenCoyote Labs Web Site", getMySite);
So here we have added a separator before the copyrightNotice CM item, and we declared a new CM item "mySiteLink" This is using the other function we made earlier, "getMySite"
So we are done then! Publish, test and.. oh dear god, nothing has changed! That because we have to "push" the new items through Flash to the Flash Player. We do that with the "push" command (again, original, I know)
Code:
myMenu.customItems.push(mySiteLink, copyrightNotice, copyProtect);
_root.menu = myMenu;
So as you can see, this is the ORDER that matters, not when we declare the variables, but in the PUSH command. this is the order we will see the CM items. Make sure they are all there, and you can move them around however you like.
Now we are done. Save, publish upload, and you will have something like the one seen right here
Here is the whole code in one snippet:
Code:
/**** My Context Menu*****/
function noClick() {
}
function getMySite() {
getURL("http://frozencoyotelabs.com", "_blank");
}
var myMenu:ContextMenu = new ContextMenu();
myMenu.hideBuiltInItems();
var copyrightNotice:ContextMenuItem = new ContextMenuItem("© 2005 - 2008 FrozenCoyote Labs", noClick);
var copyProtect:ContextMenuItem = new ContextMenuItem("No reproduction without permission of FCL", noClick);
copyrightNotice.separatorBefore = true;
var mySiteLink:ContextMenuItem = new ContextMenuItem("FrozenCoyote Labs Web Site", getMySite);
myMenu.customItems.push(mySiteLink, copyrightNotice, copyProtect);
_root.menu = myMenu;
/*****End My Context Menu******/
Enjoy!
Bookmarks