问题
This is my AS3 code for a textbox with an instance name of myTextBox
placed on stage -:
import flash.display.*;
import flash.events.*;
myTextBox.text = 'Hello India';
myTextBox.addEventListener(Event.PASTE, onPaste)
function onPaste(e:Event):void
{
trace("lol");
}
But when i paste some text into the text box, nothing happens. Can't figure out the issue. Thanks for help...
回答1:
According to the documentation http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/Event.html#PASTE:
Note: TextField objects do not dispatch clear, copy, cut, paste, or selectAll events. TextField objects always include Cut, Copy, Paste, Clear, and Select All commands in the context menu. You cannot remove these commands from the context menu for TextField objects. For TextField objects, selecting these commands (or their keyboard equivalents) does not generate clear, copy, cut, paste, or selectAll events. However, other classes that extend the InteractiveObject class, including components built using the Flash Text Engine (FTE), will dispatch these events in response to user actions such as keyboard shortcuts and context menus.
So the easiest option is to use a TLF TextField. (Make sure to publish for Flash Player 10)
来源:https://stackoverflow.com/questions/16559409/dispatch-paste-event-in-as3