如何在ActionScript 3.0中捕获鼠标单击 [英] how to capture mouseclick in actionscript 3.0

查看:130
本文介绍了如何在ActionScript 3.0中捕获鼠标单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用ActionScript 3.0在Flash窗口中捕获用户的鼠标单击位置?

How do I capture the position of a mouseclick from the user in my Flash window using Actionscript 3.0?

推荐答案

罗恩·德维拉(Ron DeVera)很近,但是我不会使用内联函数,并且传递给该函数的对象不是事件,而是MouseEvent.

Ron DeVera is close, but I wouldn't use an inline function, and the object passed to the function is not Event, but MouseEvent.

stage.addEventListener(MouseEvent.CLICK, _onStageMouseDown);

function _onStageMouseDown(e:MouseEvent):void
{
    trace(e);
}

//traces
//[MouseEvent type="click" bubbles=true cancelable=false eventPhase=2 localX=96 localY=96 stageX=96 stageY=96 relatedObject=null ctrlKey=false altKey=false shiftKey=false buttonDown=false delta=0]

上面输出中的所有属性都可以通过传递给事件侦听器方法_onStageMouseDown(e:MouseEvent);的对象获得.因此,以下

All of the properties in the output above are available through the object that gets passed to the Event Listener Method, _onStageMouseDown(e:MouseEvent); Hence the following

function _onStageMouseDown(e:MouseEvent):void
{
    trace(e.localX);
    trace(e.stageX);
    //Note that the above two traces are identical as we are listening to the stage for our MouseEvent.
}

这篇关于如何在ActionScript 3.0中捕获鼠标单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆