如何在actionscript/flex3中手动触发点击事件?

发布于 2024-10-02 19:49:13 字数 186 浏览 3 评论 0原文

类似于 JavaScript 中的以下内容:

<input id="target" type="button" onclick="..." />

<script>
document.getElementById('target').click();
</script>

Similar to the below in javascript:

<input id="target" type="button" onclick="..." />

<script>
document.getElementById('target').click();
</script>

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

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

发布评论

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

评论(3

一笔一画续写前缘 2024-10-09 19:49:13

您可以使用dispatchEvent函数:
http://livedocs.adobe.com/flex/3 /html/help.html?content=events_07.html

您应该在触发之前创建 click 事件的新实例

You can use dispatchEvent function :
http://livedocs.adobe.com/flex/3/html/help.html?content=events_07.html

You should create a new instance of the click event event before firing

黎夕旧梦 2024-10-09 19:49:13
package 
{
    import flash.display.DisplayObject;
    import flash.events.MouseEvent;

    public class ClickEventExample
    {
        public static function dispatchClickEventFrom(something:DisplayObject):void
        {
            something.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
        }
    }
}
package 
{
    import flash.display.DisplayObject;
    import flash.events.MouseEvent;

    public class ClickEventExample
    {
        public static function dispatchClickEventFrom(something:DisplayObject):void
        {
            something.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
        }
    }
}
不知所踪 2024-10-09 19:49:13

这有什么意义呢?我建议在这种情况下使用自定义事件,这样您就不会因为 MouseEvent.CLICK 根本不代表点击而感到困惑。

如果,就像 ivo 建议的那样,您想在用户第一次滚动您的剪辑时触发一个事件,这应该可以帮助您开始:

myClip.addEventListener( MouseEvent.ROLL_OVER, handleFirstMouseOver );

function handleFirstMouseOver( e:MouseEvent ) : void
{
    dispatchEvent( new Event('mySpecialEvent', true ) );
    myClip.removeEventListener( MouseEvent.ROLL_OVER, handleMouseOver );
}

如果(并且我不假设您是:))您正在尝试伪造一个 CLICK 来绕过弹出窗口-up 拦截器或进入全屏模式或其他东西,然后再想一想,因为玩家会识别出此类事件实际上并非由用户输入产生。

what is the point of this? i would recommend using a custom event in this case, so you do not confuse yourself with MouseEvent.CLICK not representing a click at all.

if, like ivo suggests, you want to fire an event when the user first rolls over your clip, this should get you started:

myClip.addEventListener( MouseEvent.ROLL_OVER, handleFirstMouseOver );

function handleFirstMouseOver( e:MouseEvent ) : void
{
    dispatchEvent( new Event('mySpecialEvent', true ) );
    myClip.removeEventListener( MouseEvent.ROLL_OVER, handleMouseOver );
}

If (and I am not assuming you are :) ) you are trying to fake a CLICK to get around pop-up blockers or enter FullScreen mode or something, then think again, because the player will recognize such events as not actually spawned from user input.

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