Dispatch Paste Event in AS3

南笙酒味 提交于 2020-01-15 10:29:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!