Custom context menus on Lists: Flex 2 Beta 2
Here’s a simple example of how to add custom context menu items to your application.
It’s a little awkward on a List-based component to capture the list item where the context menu was brought up.
I’ve heard of people capturing and storing the rollOver events on the list, and you then know that the last item rolled over is the one where the context menu was brought up.
But, if your lists itemRenderer implements mx.controls.listClasses.IDropInListItemRenderer, you can get the selectedIndex from the listData without having to pay attention to rollOver events.
This example will trace the selected list items label and rowIndex, and the caption of the selected context menu item.
Because I was using an itemRenderer it got a little weird once I was trying to get the target list item. If you right-click on the actual label in the list, the events mouseTarget is UITextField, but if you right-click on the renderer itself then the events mouseTarget is the listRenderer that you want. So here’s how I check for that…
/* The user may click right on an object inside the renderer
* ... in our case it would be the label. If so, the target is the UITextField
*/
if( ! (target is listRenderer) )
{
selectedListRenderer = target.parent.parent;
// otherwise they are clicking right on the renderer itself...
// ( outside of the label )
} else {
selectedListRenderer = listRenderer(event.mouseTarget);
}
I haven’t tested this with any other objects in the itemRenderer. It sure ould be nice if this worked no matter what the contents of the itemRenderer are.
Click here to view the source

April 6th, 2006 at 11:20 pm
hi, thanks for this example, but I can’t see the source. Is this example builded with beta 2?
April 7th, 2006 at 12:28 am
Sorry about that, I just fixed it.
April 7th, 2006 at 8:46 pm
Are you a member of the GT Crew on the midnight prowl? This is BBLDD.
April 7th, 2006 at 11:03 pm
What? Luke-Dawg? Is this all of a sudden becoming a meet old friends site? Dang. Let’s take this off-line.
April 9th, 2006 at 3:31 am
Are you able to add more than 2 custom items to the context menu? I’m get 2 max. Strange. Thanks.
-James
April 4th, 2008 at 10:42 pm
Hello, excellent site, very rich in content
and correctly carefully thought out,
personally I found here much interesting
and useful
April 7th, 2008 at 10:02 pm
Hello! Excellent site! Searched a long ago
April 19th, 2008 at 11:14 am
Hello! Good site, simply super!
April 20th, 2008 at 10:25 am
Hello, excellent site, very rich in content and correctly carefully thought out
April 21st, 2008 at 7:06 pm
The good convenient site is made.