有没有办法在 Flash 中的静态文本字段上捕获 MOUSE_UP 事件?
当用户按下鼠标并在具有可选文本的静态文本字段上释放鼠标时,不会触发 MOUSE_UP 事件 - 不会在舞台上或其他地方触发。
当我在带有嵌套静态文本字段的影片剪辑上使用滚动条类时,我遇到了这种情况。 当用户拖动滚动手柄并在文本字段上释放鼠标时,拖动/滚动会被卡住。
要对此进行测试,请创建一个新的 AS3 fla 文件,在某处放置一个静态文本字段,然后输入一些文本。确保在属性面板中选中了可选属性。 将此脚本添加到时间线:
import flash.events.*
function down(event:Event):void { trace('down'); }
function up(event:Event):void { trace('up'); }
stage.addEventListener(MouseEvent.MOUSE_DOWN, down)
stage.addEventListener(MouseEvent.MOUSE_UP, up)
现在测试影片并单击鼠标。您会注意到,当您在文本字段上释放鼠标时,不会发生trace('up')。
When the user presses the mouse, and releases it over a static textfield with selectable text, no MOUSE_UP event is fired - not on the stage and also nowhere else.
I experienced this when using a scrollbar class on a movieclip with a nested static textfield.
When the user drags the scroll handle and releases the mouse over the textfield, the dragging/scrolling is stuck.
To test this, create a new AS3 fla file, place a static textfield somewhere, and put in some text. Make sure the selectable property is checked in the properties panel.
Add this script to the timeline:
import flash.events.*
function down(event:Event):void { trace('down'); }
function up(event:Event):void { trace('up'); }
stage.addEventListener(MouseEvent.MOUSE_DOWN, down)
stage.addEventListener(MouseEvent.MOUSE_UP, up)
Now test the movie and click the mouse. You will notice that trace('up') will not occur when you release the mouse over the textfield.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简短的答案是否定的,尽管您可以尝试循环遍历舞台的显示列表并向其中添加鼠标事件。
将鼠标事件分配给具有您可以引用的实例名称的动态文本字段。
当在未添加事件侦听器的文本字段上释放鼠标时,不从舞台分派任何事件是正确的行为。毕竟,您的文本字段位于舞台顶部。
希望这有帮助。
The short answer is no, although you could attempt to loop through the stage's display list and add mouse events to it.
Assign mouse events to a dynamic text field with an instance name you can reference to.
It is a correct behaviour to not have any events dispatched from the stage when releasing the mouse over a text field with no event listeners added to it. After all, your text field is sitting on top of the stage.
Hope this helps.
有一种方法,但你必须稍微捏造一些东西。
1.在文本字段上添加一个精灵,现在收到 MOUSE_UP 事件,但文本不再可选。
2.当覆盖精灵上收到 MOUSE_DOWN / MOUSE_MOVE 事件时,使用指向“hitTestTextNearPos”和“setSelected”的 TextSnapshot 类来选择静态文本字段内的文本。
您现在有一个可选择的静态文本字段,可以在其顶部触发 MOUSE_UP。
可能需要自定义指针(选择)才能完美模拟该行为。
There is a way but you'll have to fudge things up a bit.
1.Add a Sprite over the textfield, now the MOUSE_UP event is received but the text is not selectable anymore.
2.Use the TextSnapshot class pointing on "hitTestTextNearPos" and "setSelected" to select the text inside the static textfield when MOUSE_DOWN / MOUSE_MOVE events are received on the overlaying sprite.
You now have a selectable static text field that fires MOUSE_UP on top of it.
A custom pointer ( selection ) may be needed to emulate the behavior perfectly.