I think there should be a way to use anonymous functions, but in in this case anonymous function would be relatively inefficient.
Instead I would try to map the label to the id. When an item is selected you can determine the label which determines the id. So something like this: var mapping:Object = new Object(); function addMyContextMenuItem(label:String, id:String):void { // called by loop mapping[label] = id; var menuItem = new ContextMenuItem(label); menuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT ,contextMenuListner); contextMenu.builtInItems.push(menuItem) } function contextMenuListner(event:ContextMenuEvent):void { var id:String = mapping[event.target.caption]; // continue processing } Dan Freiman nondocs <http://nondocs.blogspot.com> On 5/10/07, Sebastian Feher <[EMAIL PROTECTED]> wrote:
Hi All, I'm in a situation where I need to dynamically add a number of items from an array to a ContextMenu. Each menu item has a localized label and an id. All ContextMenuItem(s) point to the same function as they are added in a loop. Once in the function ContextMenuItem has only the label - how do I preserve the id? The ContextMenuItem is final so extending it is not an option, I tried to redirect through an anonymous inlined function but that got me nowhere. Anyone bumped into this before? Regards, Sebastian PS: I do have a workaround - a very ugly one though - locally key on the label to get the id..