| Previous | Next |
Context Sensitive Menus
This sample shows how to create context sensitive menus.
The basic idea is to set the menu for the context on the fly in the movieclip's onRollover event. The code below is a snippet from the online sample. This code first defines the "menu create" functions for each context including the Windows System Tray and Mac Status Icons. Then the onRollover events are defined for each context (movieclip). And lastly, to sort out and handle menu clicks for each context, the mMenu.onCommand function is defined .
// AS 2.0 Sample Code
// application context menu -- this function will be called by the application window's
// onRollover event to set the application right-click menu
function setDefaultApplicationRightClickMenu() {
mMenu.removeAllItems("Right Click Menu");
mMenu.addItem("application 1", "Right Click Menu");
mMenu.addItem("application 2", "Right Click Menu");
mMenu.addItem("application checkable item", "Right Click Menu");
mMenu.addItem("application 4", "Right Click Menu");
mMenu.addItem("application 5", "Right Click Menu");
mMenu.addItem("application 6", "Right Click Menu");
mMenu.addItem("application 7", "Right Click Menu");
mMenu.addItem("application 8", "Right Click Menu");
mMenu.addItem("application 9", "Right Click Menu");
mMenu.addItem("application 10", "Right Click Menu");
mMenu.checkItem("application checkable item", applicationCheckItemState, "Right Click Menu");
}
// circle context menu -- this function will be called by the circle's onRollover event
// to set the circle's right-click menu
function setCircleRightClickMenu() {
var menuName:String = "Right Click Menu";
mMenu.removeAllItems(menuName);
mMenu.addItem("circle 1", menuName);
mMenu.addItem("circle 2", menuName);
mMenu.addItem("circle 3", menuName);
mMenu.addItem("circle 4", menuName);
mMenu.addItem("circle 5", menuName);
mMenu.addItem("circle 6", menuName);
mMenu.addItem("circle 7", menuName);
mMenu.addItem("circle 8", menuName);
mMenu.addItem("circle checkable item", menuName);
mMenu.addItem("circle 10", menuName);
mMenu.addItem("circle 11", menuName);
mMenu.removeItem("circle 11", menuName);
mMenu.checkItem("circle checkable item", circleCheckItemState, menuName);
}
// square context menu -- this function will be called by the square's onRollover event
// to set the square's right-click menu
function setSquareRightClickMenu() {
mMenu.removeAllItems();
mMenu.addItem("square 1");
mMenu.addItem("square 2");
mMenu.addItem("square 3");
mMenu.addItem("square 4");
mMenu.addItem("square checkable item");
mMenu.addItem("square 6");
mMenu.addItem("square 7");
mMenu.addItem("square 8");
mMenu.addItem("square 9");
mMenu.addItem("square 10");
mMenu.addItem("square 11");
mMenu.removeItem("square 11");
mMenu.checkItem("square checkable item", squareCheckItemState);
}
//
// create context menu for right-clicks on the Windows system tray icon
function createASystemTrayMenu() {
mMenu.removeAllItems("System Tray Menu");
mMenu.addItem("system tray checkable item", "System Tray Menu");
mMenu.addItem("system tray item 2", "System Tray Menu");
mMenu.addSeparator("System Tray Menu");
mMenu.addItem("system tray item 3", "System Tray Menu");
mMenu.addItem("system tray item 4", "System Tray Menu");
mMenu.checkItem("system tray item 4", true, "System Tray Menu");
mMenu.checkItem("system tray checkable item", systemTrayCheckItemState, "System Tray Menu");
}
createASystemTrayMenu();
//
// Define Rollover events
//
circle_mc.onRollOver = function() {
setDefaultApplicationRightClickMenu();
};
square_mc.onRollOver = function() {
setDefaultApplicationRightClickMenu();
};
application_mc.onRollOver = function() {
setDefaultApplicationRightClickMenu();
};
//
// handle menu clicks
//
mMenu.onCommand = function(menuName:String, itemName:String) {
mApplication.trace("inside mMenu.onCommand event handler ("+menuName+","+itemName+")");
if (itemName.indexOf("checkable") >=0) {
mApplication.trace("is checkable item in "+menuName);
if (itemName.indexOf("application") >=0) {
applicationCheckItemState = !applicationCheckItemState;
} else if (itemName.indexOf("square") >=0) {
squareCheckItemState = !squareCheckItemState;
} else if (itemName.indexOf("circle") >=0) {
circleCheckItemState = !_root.circleCheckItemState;
} else if (itemName.indexOf("system") >=0) {
systemTrayCheckItemState = !_root.systemTrayCheckItemState;
mMenu.checkItem("system tray checkable item", systemTrayCheckItemState, "System Tray Menu");
}
}
};
You can download this sample, "contextMenu", from the mProjector Samples page -- /software/flash-projector/flas.html#contextMenu.
| Questions or Feedback? | Previous | Next |
More Information
Getting Started
ActionScript 3.0 Support
- AS2 Migration
- Getting Started - Flash
- Debugging in Flash
- Building your application from inside Flash
- Getting Started - Flex
- Debugging in Flex
ActionScript 3.0 Samples
Using mProjector
- Using mProjector - Compile Your SWF into an Appli
- Customizing The About Window
- Debugging Your Application
- Launching Application at Startup
- Mac vs. Windows Application Development
- Menus
- Dynamic Window Creation
ActionScript 2.0 Samples
- Application Basics
- mProjector Class Basics
- Add Remove Programs Control Panel
- Fullscreen and Center
- Check Connection and Download File
- Choose Files
- Creating an Installer
- Creating and Controlling Multiple Windows
- Cut, Copy, and Paste (Windows)
- Desktop Shortcut and Start Menu Support
- Drag and Drop Files
- Embedding HTML and other Media types
- Flash-Shaped Windows
- Message Box
- Open Documents
- Project Files
- Reading and Writing to Hard Drive
- Startup Application
- Wallpaper and Screensaver
- Window to Window Communications
- Working with Included Files
- Context Sensitive Menus
- Alert User
- Screen Resolution
