Adobe Flash allows you to hide most of the built-in right-click context menu items and create your own custom menu items. Here is a brief example of how you can create a customized right-click context menu in SwishMax 3. This example differs from my Dynamic Context Menu in that this example does not detect which menu item is active. This example simply allows you to create custom menu items which serve specific and static functions.
To begin, you should have the latest SwishMax 3.
- In SwishMax 3 (SM3) you’ll need to create a new empty movie clip (or sprite) in your existing project. Or, you can start a new project and insert a new movie clip.
- Select the Properties tab for the new Movie Clip and give it a unique name.
- Select the “Script” tab where you will insert custom scripting.
- Copy and Paste the following script to your new Movie Clip.
/**
*
* Custom Context Menu
* Version 1.0.0
* ©2010 Jason Lau - http://JasonLau.biz
* Based on a work at http://JasonLau.biz
*
* This program is free software licensed under the CC-GNU GPL version 2.0 or later.
* The CC-GNU GPL can be found at http://creativecommons.org/licenses/GPL/2.0/.
* The GNU General Public License is a Free Software license. Like any Free Software license, it grants to you the four following freedoms:
1. The freedom to run the program for any purpose.
2. The freedom to study how the program works and adapt it to your needs.
3. The freedom to redistribute copies so you can help your neighbor.
4. The freedom to improve the program and release your improvements to the public, so that the whole community benefits.
* You may exercise the freedoms specified here provided that you comply with the express conditions of this license. The principal conditions are:
1. You must conspicuously and appropriately publish on each copy distributed an appropriate copyright notice and disclaimer of warranty and keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of the GNU General Public License along with the Program. Any translation of the GNU General Public License must be accompanied by the GNU General Public License.
2. If you modify your copy or copies of the program or any portion of it, or develop a program based upon it, you may distribute the resulting work provided you do so under the GNU General Public License. Any translation of the GNU General Public License must be accompanied by the GNU General Public License.
3. If you copy or distribute the program, you must accompany it with the complete corresponding machine-readable source code or with a written offer, valid for at least three years, to furnish the complete corresponding machine-readable source code.
* Permissions beyond the scope of this license may be requested at http://jasonlau.biz/home/contact-me.
*/
onSelfEvent (load) {
myMenu = [];
// Config below
myMenu[1] = ["Test Item 1", item_1_function, false];
function item_1_function(){
trace("Hit 1");
}
myMenu[2] = ["Test Item 2", item_2_function, true];
function item_2_function(){
trace("Hit 2");
}
myMenu[3] = ["Test Item 3", item_3_function, false];
function item_3_function(){
trace("Hit 3");
}
myMenu[4] = ["Test Item 4", item_4_function, false];
function item_4_function(){
trace("Hit 4");
}
myMenu[5] = ["Test Item 5", item_5_function, true];
function item_5_function(){
trace("Hit 5");
}
// End config
buildMenu(myMenu);
}
function buildMenu(myMenu:Array){
var rootMenu = new ContextMenu();
rootMenu.hideBuiltInItems();
i = 1;
while(myMenu[i] != undefined){
eval("newItem"+i) = new ContextMenuItem(myMenu[i][0], myMenu[i][1]);
if(myMenu[i][2] == true) eval("newItem"+i).separatorBefore = true;
rootMenu.customItems.push(eval("newItem"+i));
i++;
}
_root.menu = rootMenu;
}
That’s basically it. Now, it just needs to be configured to suit your needs.
To make it work, I wrote a function named “buildMenu” which will
assemble the context menu from arrays which are configured in the onSelfEvent
(load) function where noted in my code.
To begin, I create an empty array -
Then I add menu item arrays to the “myMenu” array.
To explain the menu item array further -
Note: There is no need to begin your array key at 0. My function allows
you to begin the array at key 1 as to avoid confusion. This way the array key
corresponds with the menu item position.
The first value in the menu item array is the text caption. You can use almost
any text for the caption.
The second value in the menu item array is the name of the function that will
be executed when the menu item is selected. This function can serve most any
purpose, such as movie control or javascript.
The third value in the menu item array is a Boolean value (true or false) which
will control if there is a horizontal separator inserted before the menu item.
This is helpful if you want to create groups of menu items.
In my script, each menu item array has a function directly below it.
Example -
trace(“Hit 1″);
}
You should notice that the function name corresponds with the second value in
the menu item array. The name in the example above is “item_1_function”.
You will also find that same name in the menu item array -
The action for the menu item in this example is -
That will simply add text to the debug panel in SM3 as a demonstration. You could replace the trace function with any function you need to execute or keep it for debugging.
In my example code, I included five sample menu items for you. You can test
it by playing the movie and using your mouse to right-click anyplace on the
movie.


