2013-04-07 93 views
1

我想鼠標點擊屏幕座標(點擊以外的AIR應用程序窗口)讓鼠標點擊screenX和screenY在AS3

我嘗試以下,但我沒有得到任何東西,它看起來像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 :(
} 
+0

我以前從來沒有使用'ScreenMouseEvent',但它看起來像它只是從'SystemTrayIcon'類調度。你可能必須以某種方式添加你的監聽器。 文檔的ScreenMouseEvent:http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/ScreenMouseEvent.html – 2013-04-08 01:26:42

回答

0

ScreenMouseEventSystemTrayIcon唯一(的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); 

注意的ScreenMouseEvent產生的screenXscreenY屬性在托盤中的圖標面積內,而不是整個桌面屏幕(毫不奇怪,因爲這是您首先添加事件的地方)。