View Full Version : Problem with custom context menu (Flash CS3/AS3)

10-01-2007, 07:35 PM
I am attempting to implement a custom context menu in a Flash CS3 and ActionScript 3 project.

PROBLEM: The context menu displays and functions properly when testing the movie in Flash CS3 but does not display at all when viewing through my website (IE7 or Firefox).

Has anybody seen this before?

Here is a sample of some of the code I'm using. The context menu is created inside of the class where I have a few display objects.

public class MyClass
protected var m_ContextMenu:ContextMenu;

function MyClass()
//--- Build Context Menu
m_ContextMenu = new ContextMenu();

var item:ContextMenuItem = new ContextMenuItem("TestItem");


item.addEventListener(ContextMenuEvent.MENU_ITEM_S ELECT, menuItemSelectHandler);

m_ContextMenu.addEventListener(ContextMenuEvent.ME NU_SELECT, menuSelectHandler);

protected function menuSelectHandler(event:ContextMenuEvent):void
trace("menuSelectHandler: " + event);

protected function menuItemSelectHandler(event:ContextMenuEvent):void
trace("menuItemSelectHandler: " + event);

10-01-2007, 09:42 PM
I've simplified the problem to this.

In my .fla file I do do the following:

var cm:ContextMenu = new ContextMenu();
var item:ContextMenuItem = new ContextMenuItem('Test Item');
MyMovieClip.contextMenu = cm;

When I run this in Flash CS3 it works no problems. Right click context menu pops up with 'Test Item' in it. However, when I run it through IE7 or Firefox, I don't get anything.


10-02-2007, 04:06 PM
I failed to mention that I am attempting to display this in an ASP.NET website. I am using Bewise's FlashControl to display the swf. Everything works fine (.NET Remoting, all display object visble, etc., etc.) except for the custom context menu.

The simple example I provided previously works fine for the following:

- Running from within Flash CS3 (Test Movie)
- Publish Preview from Flash CS3 (both using Player 9 and straight HTML)

It simply will not display the custom context menu item when running in my ASP.NET website (both from within VS2005 debug environment or fully published website). :mad:

10-09-2007, 03:19 PM
//hide the visibility of my MovieClip that show after pick the item with contexmenu, you need creat a movieClip and put a istance name

var myMenu:ContextMenu = new ContextMenu();
//creating an item
var item1:ContextMenuItem = new ContextMenuItem("1 Test Item");
//creating more items, the same way that
var item2:ContextMenuItem = new ContextMenuItem("2 Test Item");
var item3:ContextMenuItem = new ContextMenuItem("3 Test Item");

//push the items customs that we created. just put between "()" the name each item that you created
myMenu.customItems.push(item1, item2, item3);

//hide the standard items. Last 3 items is standard.

//give to the contextmenu, all that we defined on the var myMenu.
contextMenu = myMenu;

//give to the item1 a listener that will verify contextMenuItem and execute the Function "show_myMovieClip" that will be creat.
item1.addEventListener(ContextMenuEvent.MENU_ITEM_ SELECT, show_myMovieClip);

//function that show the MovieClip after click on the item1 from contextmenu.
function show_myMovieClip(AnyNameToparamet:ContextMenuEvent ):void

So it a simple mode. I created just the first item(item1).

This way will show the items on contextMenu and execute the function that we defined.

You need to create a ListenerEvent to each item using the method
name_Of_Your_Item.addEventListener(ContextMenuEven t.MENU_ITEM_SELECT, name_Of_Your_Function);

On the Function you need show between "()" the type of Event, in this case need to refer
the (ContextMenuEvent), after the "," you put the name of function that will be executed.
You need to make a new functions to each item that was creating if you wanna execute something on this item.

I think with this simples exemple you can use to execute what you want. Put or change for the new functions that you need.

Maybe this can give you some solution.

Good luck.

10-03-2008, 07:45 AM
Thanks, Rodrigopixel, that worked like a charm.