Skip to main content
Inspiring
April 21, 2010
Answered

Copy, Cut, Paste

  • April 21, 2010
  • 1 reply
  • 2100 views

Hi,

How can I implement cupy, cut and paste in actionscript. Basically, I have 3 buttons that I want to use to trigger those actions.

Thanks in advance.

This topic has been closed for replies.
Correct answer robin_briggs

Are you going to run this from an AIR application, or from the Flash Player in a browser? In the latter case, there are security restrictions that prevent you from accessing the clipboard unless the browser has detected a user request for Cut, Copy, or Paste (e.g., a menu hit). In an AIR application, these restrictions are not an issue.

I'd suggest looking at the TextScrap and TextClipboard classes as well as the EditManager. The TextClipboard has basic functions for getting content to and from the system clipboard. The TextScrap is a data structure used for copy & paste that's essentially a snippet of text from within a TextFlow.

For Copy, you can do a CopyOperation, or you can just do this:

                TextClipboard.setContents(TextScrap.createTextScrap(selectionState));      

The selectionState indicates the range of text to be copied.

For Paste or Cut, easiest way is through the EditManager, assuming your textFlow's interactionManager is an EditManager:

               EditManager(textFlow.interactionManager).pasteTextScrap(TextClipboard.getContents());

and

               TextClipboard.setContents(EditManager(textFlow.interactionManager).cutTextScrap());      

Hope this helps,

- robin

1 reply

robin_briggsCorrect answer
Adobe Employee
April 21, 2010

Are you going to run this from an AIR application, or from the Flash Player in a browser? In the latter case, there are security restrictions that prevent you from accessing the clipboard unless the browser has detected a user request for Cut, Copy, or Paste (e.g., a menu hit). In an AIR application, these restrictions are not an issue.

I'd suggest looking at the TextScrap and TextClipboard classes as well as the EditManager. The TextClipboard has basic functions for getting content to and from the system clipboard. The TextScrap is a data structure used for copy & paste that's essentially a snippet of text from within a TextFlow.

For Copy, you can do a CopyOperation, or you can just do this:

                TextClipboard.setContents(TextScrap.createTextScrap(selectionState));      

The selectionState indicates the range of text to be copied.

For Paste or Cut, easiest way is through the EditManager, assuming your textFlow's interactionManager is an EditManager:

               EditManager(textFlow.interactionManager).pasteTextScrap(TextClipboard.getContents());

and

               TextClipboard.setContents(EditManager(textFlow.interactionManager).cutTextScrap());      

Hope this helps,

- robin

oscar7878Author
Inspiring
April 22, 2010

Thanks Robin!