apache-flexactionscript-3flex3

Ctrl + C not working in flash player(swf file) when browser is Google Chrome


I have my project developed in Flex3,

<<Site Link Removed now>>

You can check it here, the problem I'm facing is, copying(Ctrl + c) the content from screen textarea when the swf is running in chrome browser.

suppose, I have to add some text on the stage, so the text area which is opened on the left side, I can't copy the text written in text area, although by right clicking in textarea, and selecting the copy option, thats working, but my client has asked for copying the content by using Ctrl + c, although it's working very fine with other browsers,

only chrome is not supporting copying(Ctrl + c), although selecting all(Ctrl + A ) is working

So this the thing, which I thought I should discuss, may b someone also hav same problem,


Solution

  • Use KeyboardEvent.KEY_DOWN to detect "C" being pressed. Then check for ctrlKey to see if it is down, and use System.setClipboard(source.text); to set the clipboard content.

    textArea.addEventListener (KeyboardEvent.KEY_DOWN, onKeyDown);
    
    private function onKeyDown ( ev : KeyboardEvent ) : void 
    {
        if (ev.keyCode != 67 || !ev.ctrlKey) return;
        var text:String = textArea.text;
        System.setClipboard( text);
    }
    

    Beware, though: Sometimes odd things can happen simultaneously, like the text content disappearing and such. You might have to work around that!