Total Pageviews

Sunday 14 June 2015

AS3 :: Paste the Copied Text into a TextField on Stage


Since Flash Player 10, flash embedded on websites apps are just able to access to the Clipboard.generalClipboard.getData() method just when they are processing a PASTE event dispatched directly by the user.

Below is the example : 

package
{
    import flash.display.Sprite;
    import flash.desktop.Clipboard;
    import flash.desktop.ClipboardFormats;
    import flash.desktop.ClipboardTransferMode;
    import flash.events.*;
    import flash.system.System;

    public class ClipboardExample extends Sprite
    {
       public function ClipboardExample()
       {  
           Clipboard.generalClipboard.clear();
           copyButton.addEventListener(MouseEvent.MOUSE_UP, copyText);
       }

       private function copyText(e:MouseEvent):void
       {
           Clipboard.generalClipboard.clear();
           System.setClipboard(myField.text);
           messageField.text = "Copied!";
           stage.addEventListener(Event.PASTE,paste); //Ctrl+V on stage
       }    

       private function paste(e:Event):void
       {
          if(Clipboard.generalClipboard.hasFormat(ClipboardFormats.TEXT_FORMAT))
          {              
             messageField.text =String(Clipboard.generalClipboard.getData(ClipboardFormats.TEXT_FORMAT));
          }
      }
   }  
 }

No comments:

Post a Comment

Microsoft Logo using flexbox and Reactjs

 <!DOCTYPE html> <html> <head>     <script src="https://unpkg.com/react@18/umd/react.development.js" crossori...