Skip to main content
October 16, 2009
Question

Create a PASTE event.

  • October 16, 2009
  • 2 replies
  • 3211 views

Flash says I can only use the Clipboard.getData only in a PASTE event. (CS4 & AS3)

But I don't know how to make a paste event? Can someone help me out?

This topic has been closed for replies.

2 replies

October 17, 2009

No one kows this? Because Flash says I can only do it within a PASTE event, so there should be a way to make a paste event right?

Inspiring
October 17, 2009

I'd see it as a security breach if any app on the interwebs could read my clipboard without me going Ctrl/Cmd-V...

No tellin' what's on the clipboard: passwords, CC numbers etc.

In other words, I would not be surprised if it was not possible.

October 17, 2009

Yeah but read this:http://drawlogic.com/2008/09/28/flas...save-and-load/

It says: the new ActionScript 3.0 method Clipboard.generalClipboard.getData() may be used to read the contents of the system Clipboard, but only when it is called from within an event handler processing a flash.events.Event.PASTE event.

And even Flash itself says: you can only do this within a Paste event.. so it IS possible?

Inspiring
October 16, 2009

Use

System.setClipboard( strToCopy )

October 16, 2009

I want to access the clipboard to get the text out of it. I can already do it in AIR but to do it in a swf it needs to happen in a paste event.

But I don't know how to make a PASTE event..

function onPasteMessage(event:Event) {
    trace("lol");
}
myTextField.text = "LOL";
myTextField.addEventListener(Event.PASTE, onPasteMessage);

I tried that code with an textfield called myTextField on the stage, but when I rightclick and select Paste nothing happens.

Inspiring
October 17, 2009

First make sure that type of the tet field is "input". Programmatically is can be done:

myTextField.type = TextFieldType.INPUT;

Once it is done - it will show OS context menu (Copy, Paste, etc.)

According to documentation TextField doesn't dispatch Event.PASTE. Read this:

http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/events/Event.html#PASTE

If you want to detect changes in the TextField you may want to listen to Event.CHANGE.