There are so many new features in Flash MX 2004 that I haven’t even gotten around to looking at some of them. I knew there was a way to play with the “right-click menu” in there, but just recently started digging into it. Since I haven’t seen much about it, I figured I’d write up what I found, so people will realize how easy it is to customize this element.
- The first thing you need to know is that Buttons, TextFields and MovieClips (including components, _root, and _levels) now have a new property called, “menu”. This is an object that represents that right-click menu.
- Rather than directly messing with this object, you need to make a new instance of a ContextMenu object, and assign that to the menu property of the element you want to affect. This looks something like this:
var myMenu:ContextMenu;
myMenu = new ContextMenu();
_root.menu = myMenu; - Now you can start messing with the menu. The main thing that anyone wants to do is to hide the built in items that are usually seen on that menu. This is done like so:
var myMenu:ContextMenu;
myMenu = new ContextMenu();
_root.menu = myMenu;
myMenu.hideBuiltInItems();Note that you can’t get rid of the “Settings” and “About” items. Those are there to stay… at least until someone finds a way to hack them out.
- Rather than remove ALL of the built in items, you might want to just remove one or a few of them. All of the possible items that can appear on the menu are members of the “builtInItems” object which is a member of the ContextMenu object. You can just set each one to true or false to show or hide it. For instance if we wanted to hide the “Quality” menu item, we could say instead:
myMenu.builtInItems.quality = false;If you’ve set up the code as above, you should get a list of code hints showing the available options right after you type “myMenu.”.
- Next, we can set up a function that will be run whenever the right-click menu is opened. We just assign the function to the “onSelect” property of the ContextMenu object:
myMenu.onSelect = notify;
function notify() {
    trace(“You Right-Clicked!”);
}Of course, you’d probably want to set up something more useful, but you get the idea.
Well, that should be enough to spark your interest and get you playing with it. Part II will cover how to put your own items on the list and react when the user chooses them.
Try this:
Make a textfield and name it “output”.
var myMenu:ContextMenu;
myMenu = new ContextMenu();
myMenu.hideBuiltInItems();
myMenu.builtInItems.quality = false;
function notify() {
output.text = “right click”;
}
myMenu.onSelect = notify;
_root.menu = myMenu;
l
Oh,this article is very good,but 🙁 555555555.
i can’t know this meaning.oh i hate my brain!can you give me a resouse sample!thanx