悬停 AS3 上的假鼠标点击

发布于 2024-10-14 07:53:29 字数 511 浏览 2 评论 0原文

今天早上我偶然发现了这个问题:

当悬停按钮时,是否可以在 X 秒后自动单击它?那么用户不需要用鼠标点击它?

我怎样才能让Flash相信我的鼠标确实点击了舞台上的某个按钮或者是用as3调出来的?

我的电影中有很多按钮。因此,我更喜欢使用一些代码来覆盖电影中所有现有或即将出现的按钮的此功能。

我通常会使用这样的代码,但是是否有一些解决方法可以以不同的方式完成此任务?我不想为每个按钮添加代码。

this.addEventListener(MouseEvent.OVER, onMouseClickEvent);

public function onMouseClickEvent(event:Event)
{
trace(event);
if(event.buttonDown) // if button goes down normally
trace("MOUSE CLICKED NORMALLY");
else
trace("left button was not down");
}

This morning I stumbled to this question:

When hovering a button, is it possible to click it automatically after X seconds? So the user doesn't need to click it with his mouse?

How can I let Flash believe my mouse really clicked some button on the stage or brought up with as3?

I have a lot of buttons in my movie. So I prefer to use some code which will cover this function for all existing or coming up buttons in my movie.

I would normally use a code like this but is there some workaround to accomplish this in a different way? I do no want to add code to every button.

this.addEventListener(MouseEvent.OVER, onMouseClickEvent);

public function onMouseClickEvent(event:Event)
{
trace(event);
if(event.buttonDown) // if button goes down normally
trace("MOUSE CLICKED NORMALLY");
else
trace("left button was not down");
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

眉目亦如画i 2024-10-21 07:53:30

我认为最简单的方法是对 Button 进行子类化。
然后您应该添加鼠标悬停/移出侦听器,添加看起来像这样的单击侦听器
:public function clickListener(event:MouseEvent = null){...}

当鼠标悬停时,引发鼠标在对象上的标志,启动计时器,当计时器回调函数为调用时,您检查标志(当鼠标移出时将标志调低)是否为真,然后调用 clickListener()

The easiest way i think, is to subclass Button.
Then you should add mouse over/out listeners, add click listener that looks like that
:public function clickListener(event:MouseEvent = null){...}

When the mouse is hovering, raise a flag that the mouse is on the object, start a timer and when the timer callback function is called, you check the if the flag (you turn the flag down, when the mouse is out) is true and just call clickListener()

蓝戈者 2024-10-21 07:53:30

侦听 MouseEvent.MOUSE_OVER 并启动计时器,在计时器结束时按钮将发送 MouseEvent.CLICK 事件。在鼠标悬停处理程序中,使用 SystemManager 为 MouseEvent.MOUSE_OUT 添加一个侦听器,该侦听器会取消计时器。计时器也使用 SystemManager 删除侦听器。单击按钮也是如此。

Listen for MouseEvent.MOUSE_OVER and start a timer, at the end of which the button will send the MouseEvent.CLICK event. In the mouseover handler, use the SystemManager to add a listener for MouseEvent.MOUSE_OUT which cancels the timer. The timer removes the listener using the SystemManager as well. So does clicking the button.

清风夜微凉 2024-10-21 07:53:30

最后!解决了!

这成功了:

public function runOnce(event:TimerEvent):void {
btnSignal.dispatch("键盘", btnCode);
}

罗布斯托 &拉多斯拉夫·格奥尔基耶夫:感谢您指明了正确的方向!

Finally! Solved!

This did the trick:

public function runOnce(event:TimerEvent):void {
btnSignal.dispatch("KEYBOARD", btnCode);
}

Robusto & Radoslav Georgiev: Thank you for pointing the right direction!

情话已封尘 2024-10-21 07:53:30

(我回答这个问题有点晚了,但想为未来的人提供意见)。

“给这只猫剥皮”的一种方法是简单地让悬停事件触发计时器(即 3 秒)。在 EnterFrame 或其他函数中,当达到 3 秒时,让数字或布尔值发生变化。

//Pseudo code

    if(timer == 3)
{ numberVar = 1;
//or
BooleanVar = True;
}
else
{
numberVar = 0;
//or
BooleanVar = false;
}
//end

然后,就像您将方法连接到 mouseEvent 一样,连接这些相同的方法以在 numberVar == 1 或 BooleanVar == True 时触发。就是这样。

为了超级简单和可读性,让您的 MouseClickEvent 只是 numberVar = 1 或 BooleanVar = True。

随着时间的推移,这些变得非常容易实现,并且根据我的经验,它们“非常”防错。如果出现拼写错误或其他问题,也很容易修复。也没有超级难以捉摸的进口。希望有帮助。

顺便说一下,这是一个很好的问题(+ 1)

:D

(I'm answering this a little late but would like to give input for future people).

One way to 'skin this cat' is to simply let your hover event trigger a timer (i.e. 3 seconds). In an EnterFrame or other function let a number or Boolean change when 3 seconds is reached.

//Pseudo code

    if(timer == 3)
{ numberVar = 1;
//or
BooleanVar = True;
}
else
{
numberVar = 0;
//or
BooleanVar = false;
}
//end

Then just as you connected your methods to a mouseEvent, connect those same methods to fire when numberVar == 1 or BooleanVar == True. That's it.

For super simplicity and readability let your MouseClickEvent just be numberVar = 1 or BooleanVar = True.

These become super simple to implement over time and in my experience are 'very' error proof. Easy to fix also in the case of a typo or something else. No super elusive imports either. Hope that helped.

Great question by the way (+ 1)

:D

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文