<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="/mxml/2009"
xmlns:s="library:///flex/spark"
xmlns:mx="library:///flex/mx"
creationComplete="initApp()">
<s:layout>
<s:HorizontalLayout horizontalAlign="center" verticalAlign="middle"/>
</s:layout>
<fx:Script>
<![CDATA[
import ;
import ;
import ;
import ;
private var myContextMenu:ContextMenu;
private function initApp():void
{
popUpMenu();
}
private function popUpMenu():void
{
myContextMenu = new ContextMenu();
removeDefaultItems();
addCustomMenuItems();
// Listen to the event after the right-click menu pops up
(ContextMenuEvent.MENU_SELECT, menuSelectedHandler);
= myContextMenu;
}
//Delete the original menu item
private function removeDefaultItems():void
{
();
var defaultItems:ContextMenuBuiltInItems = ;
= false;
}
//Add user-defined menu items
private function addCustomMenuItems():void
{
var item:ContextMenuItem = new ContextMenuItem("Delete Line");
//Default menu item
= false;
(item);
// Listen to events after selecting menu items
(ContextMenuEvent.MENU_ITEM_SELECT, itemSelectedHandler);
}
//Event handling function after pop-up menu
private function menuSelectedHandler(event:ContextMenuEvent):void
{
var item:ContextMenuItem = [0] as ContextMenuItem;
if ( >= 0)
{
= true;
}
else
{
= false;
}
}
//Event handling function after selecting menu item
private function itemSelectedHandler(event:ContextMenuEvent):void
{
if ( >= 0)
{
();
}
}
]]>
</fx:Script>
<s:DataGrid requestedRowCount="4"
width="500">
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="dataField1" headerText="Column 1" ></s:GridColumn>
<s:GridColumn dataField="dataField2" headerText="Column 2"></s:GridColumn>
<s:GridColumn dataField="dataField3" headerText="Column 3"></s:GridColumn>
</s:ArrayList>
</s:columns>
<s:typicalItem>
<fx:Object dataField1="Sample Data" dataField2="Sample Data" dataField3="Sample Data"></fx:Object>
</s:typicalItem>
<s:ArrayList>
<fx:Object dataField1="Data1" dataField2="Data1" dataField3="Data1"></fx:Object>
<fx:Object dataField1="Data 2" dataField2="Data 2" dataField3="Data 2"></fx:Object>
<fx:Object dataField1="Data3" dataField2="Data3" dataField3="Data3"></fx:Object>
<fx:Object dataField1="Data 4" dataField2="Data 4" dataField3="Data 4"></fx:Object>
</s:ArrayList>
</s:DataGrid>
</s:Application>