<mx:Script> <![CDATA[ private function updateMenu(index:Number):void { lastRollOverIndex = index;
// only enable the Copy menu item when the user is over a row in the DataGrid if (isNaN(lastRollOverIndex)) { menuItems.getItemAt(0).enabled = false; } else { menuItems.getItemAt(0).enabled = true; }
private function handleMenuClick(index:int):void { if (index == 0) { // add the data to the clipboard Clipboard.generalClipboard.clear(); var cs:String = dg.dataProvider[lastRollOverIndex].firstName + "\t" + dg.dataProvider[lastRollOverIndex].lastName + "\t" + dg.dataProvider[lastRollOverIndex].phone + "\r\n"; Clipboard.generalClipboard.setData(ClipboardFormats.TEXT_FORMAT, cs); } else if (index == 1) { // read the data from the Clipboard if (Clipboard.generalClipboard.hasFormat(ClipboardFormats.TEXT_FORMAT)) { var a:Array; var s:String = new String(Clipboard.generalClipboard.getData(ClipboardFormats.TEXT_FORMAT));
// split the Clipboard string into an array if (s.indexOf("\t") >= 0) a = s.split("\t"); else if (s.indexOf(" ") >= 0) a = s.split(" "); else a = [s];
// assign the Array items to a new Object var o:Object = new Object(); if (a.length > 2) o.phone = a[2];
if (a.length > 1) o.lastName = a[1];
if (a.length > 0) { o.firstName = a[0];
// add the item to the DataGrid people.addItem(o); } } } }