在as3中鼠标单击screenX和screenY

时间:2013-04-07 23:40:46

标签: actionscript actionscript-3

我想获得鼠标单击屏幕坐标(通过单击AIR应用程序窗口外部)

我尝试了以下操作,但是我没有得到任何东西,似乎没有调度ScreenMouseEvent.CLICK事件。

public function Main():void 
{   
if (NativeApplication.supportsSystemTrayIcon)//testExpression return true 
    {            
         SystemTrayIcon(NativeApplication.nativeApplication.icon).
         addEventListener(ScreenMouseEvent.CLICK, click);
    }
}

private function click(e:ScreenMouseEvent):void 
{
      trace(e.screenX);//nothing displayed :(
}   

1 个答案:

答案 0 :(得分:0)

ScreenMouseEvent仅由SystemTrayIcon调度(仅限Windows / Linux)。从SystemTrayIcon检索DockIcon实例(MacOs的NativeApplication.nativeApplication.icon)。
因此,在指定托盘图标图形后,您应该在此处附加事件监听器:

var sti:SystemTrayIcon = NativeApplication.nativeApplication.icon as SystemTrayIcon;
// Specifying an icon is obligatory on Windows - MacOs has a default icon
sti.bitmaps = [new IconAsset()]; // IconAsset = Embedded picture
sti.addEventListener(ScreenMouseEvent.CLICK, mouseClick);

请注意,screenX生成的screenYScreenMouseEvent属性仅限于托盘中的图标区域,而不是整个桌面屏幕(不出所料,因为这是您添加的位置首先是事件。)