> > Tutorials > T1076

Context menu in Flash

How to create context menu for an item in Flash.

This example demonstrates how to create right click menu for an item in Flash movie.

Download source project (3 kb)

  1. Launch Alligator Flash Designer and choose Blank
  2. Set movie dimensions to 460 x 180 (or any desired) with Frame > Frame Size
  3. Choose "Movie" > "Export Options" > "SWF Version" and set target player version: Flash Player 8

  4. Change frame delay to "Stop".
  5. Choose Sprite tool and draw a sprite, double click the sprite to edit it
  6. Inside the sprite draw a rectangle and apply any color to it, for example yellow
  7. Hit Esc to quit the sprite
  8. Select the sprite and press F2 to rename the sprite, the name should be Sprite1

  9. Choose Frame > ActionScript and paste the script
    // create new context menu
    mymenu = new ContextMenu();
    // hide items like Zoom, Play, Loop etc
    // define menu item handler
    function doFrame2() {  gotoAndPlay("Frame 2");}
    // create new menu item and add it to the right click menu
    frame2item = new ContextMenuItem("Frame 2", doFrame2);
    mymenu .customItems.push(frame2item);
    // set the menu for sprite 1 = mymenu;

  10. Add a new Frame that will appear as "Frame 2" and put anything on it, for example text "Frame 2"
  11. Hit F9 for preview. Right-click anywhere outside the rectangle to view default menu, right-click on the rectangle to open "mymenu". Choose "Frame 2" from the context menu to go to Frame 2.

Products | Purchase | Downloads | Support | Flash Tutorials | Contact
Copyright © 1999-2017 Selteco Software, Inc., ph: +1 810 377 5778