2 Replies Latest reply on Feb 3, 2010 9:39 PM by Deepa Ganesan

    Ctrl+c in Adobe AIR

    Deepa Ganesan

      Hi,

       

      I have an advanceddatagrid with selectionMode="multipleCells". When i select few cells using ctrl key and then copy the content using Ctrl+c, the cells are getting deselected automatically and the content is not getting copied. Can someone help on this. Attaching part of my code.

       

      private

       

       

      var _ctrlHoldFlag:Boolean = false;

       

       

      private function myKeyDownHandler(event:KeyboardEvent):void {

       

           if (event.ctrlKey) {

                _ctrlHoldFlag =

      true;

           }

      }

       

      private function myKeyUpHandler(event:KeyboardEvent):void

      {

           var

       

       

      keycode_c:uint = 67;

       

           var keycode_v:uint = 86;

       

           var keycode_x:uint = 88;

           if

       

       

      (_ctrlHoldFlag && (event.keyCode == keycode_c || event.keyCode == keycode_v || event.keyCode == keycode_x))

           {

                event.preventDefault();

       

                if(event.keyCode == keycode_c) {

                     copyData(event.currentTarget);

       

       

                }

           }

           if

       

       

      (event.ctrlKey) {

                _ctrlHoldFlag =

      false;

           }

       

      }

       

      public

       

       

      function copyData(objCurrentTarget:Object):void {

       

           var dataString="';

           var

       

      n1:int = objCurrentTarget.selectedCells.length;

      (Note://The value of n1 is coming as zero and hence the content is not getting copied.)

       

           for (var iCount:int = 0; iCount < n1; iCount++)

           {

       

                var cell:Object = objCurrentTarget.selectedCells[iCount];

       

                var data:Object = objCurrentTarget.dataProvider[cell.rowIndex];

       

       

                var dataField:String = objCurrentTarget.columns[cell.columnIndex].dataField;

                if(dataString != "') {

                     dataString = dataString + "|"+ data[dataField];

       

                }

           }

      }

                    

           

      Thanks in advance.

        • 1. Re: Ctrl+c in Adobe AIR
          Joe ... Ward Level 4

          I don't think there is anything specific to AIR here. You might ask this question in the Flex forum

          : http://forums.adobe.com/community/flex/flex_general_discussion


          • 2. Re: Ctrl+c in Adobe AIR
            Deepa Ganesan Level 1

            Hi Joe,

             

            Thanks for your reply.

             

            My code worked in Flex but not in AIR and hence posted the question here.

             

            When i traced the logs, i could find that event.ctrlKey is returning false in keyUpHandler event and hence it is not executing my part of code. Also keyUpHandler function is getting called multiple times and event.ctrlKey returns true only once and rest of the times it returns false. Hence, to fix this issue have used a boolean which is set to true when event.ctrlKey is true in keyDownHandler event. Used a boolean in keyDownHandler event for the key "c" also. Also as of now to fix the issue, i prevented calling keyUpHandler event multiple times and now its working fine.

             

            In flex, i have not used any booleans and event.ctrlKey and event.keyCode returns values as expetecd. But i don't know the exact reason why its working in Flex but not in AIR.

             

            Thanks

            Deepa