Avg. Rating 4.0

Problem

This entry shows you how to make a ContextMenu that interacts with the control it was popped up over - in our case, a DataGrid.

Solution

We will be popping up a flash.ui.ContextMenu over a DataGrid and exposing a menu item that allows that row's contents to be added as an item to another DataGrid control's data provider.

Detailed explanation

The full code sample can be found in the attached file.

First, we create the ContextMenu instance. By calling ContextMenu.hideBuiltInItems(), we can hide some of the items that appear in the standard Flash Player context menu.


We then create ContextMenuItem instance which will correspond to our "Buy" option. We add an event handler that handles the logic for when a user selects the Buy menu option.

The buyHandler() code is the meat of the example. It shows how to figure out what row in the DataGrid the ContextMenu was popped over and how to isolate that item in the DataGrid's data provider. We then add that item to our "Shopping Cart" DataGrid.

Report abuse

Related recipes