3 Replies Latest reply on Oct 31, 2012 10:20 AM by _darwinjob_

    Clipboard Context Menu for Datagrid Row

    asagohan

      Hello.


      I have added a context menu for my datagrid in order to paste data from the OS clipboard. It will be using flash player 10 so the clipboard can be accessed if the paste method is called from a context menu. If I copy something and then right click on an area of the datagrid without any data the paste option is available. However, if I click on a row that already has data in it, the paste option is disabled. Does anyone know how to fix this? I want to have the paste option available when I click on a row with data.

       

      <?xml version="1.0"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initComp();">

       

      <mx:Script>
      <![CDATA[
          import flash.ui.*;
          import flash.events.*;
          import mx.controls.dataGridClasses.*;
          import mx.collections.*;
         
           [Bindable] private var context:ContextMenu;
           [Bindable] private var cartList:Array = new Array();
          
          
           private function createContextMenu():void
           {
               context = new ContextMenu();
               context.clipboardMenu = true;
               context.clipboardItems.paste = true;
              
               //hasContext_mc is a movieclip on the stage
               cart.contextMenu = context;
              
               //context.addEventListener(ContextMenuEvent.MENU_SELECT, contextMenuTriggered);
               context.hideBuiltInItems();

       

             
               cart.addEventListener(Event.PASTE, pasteHandler);
               cart.addEventListener(Event.COPY, copyHandler);
               cart.addEventListener(MouseEvent.CLICK, setFocusTo);
           }   
          
           private function pasteHandler(e:Event):void
           {
               trace("Paste Handler");       
            }
                  
           private function copyHandler(e:Event):void
           {
               trace("Handling Copy Event");
           }
          
           private function setFocusTo(e:MouseEvent):void
           {
               trace("Setting focus");
               stage.focus = e.target as InteractiveObject;
           }
          
           private function initComp():void
           {
               cartList =
                [
                  { Artist:'Pavement', Album:'Slanted and Enchanted', Price:11.99, Rating:'Excellent' }
                ];

       

          createContextMenu();

       

          cart.contextMenu = context;

       

          }       
                  
      ]]>
      </mx:Script>

       

      <mx:Label text="Your Cart" />
      <mx:DataGrid showHeaders="false" horizontalGridLines="false" id="cart" dataProvider="{cartList}">
           <mx:columns>
               <mx:DataGridColumn dataField="Artist" width="120"/>
               <mx:DataGridColumn dataField="Album" width="150"/>
               <mx:DataGridColumn id="priceCol" dataField="Price" width="100"/>
           </mx:columns>
      </mx:DataGrid>

       

      </mx:Application>