Flex 中鼠标在屏幕上的位置
我试图获取屏幕上的实际鼠标坐标,以便我可以在该位置创建一个本机窗口,但我似乎无法找到正确的方法来正确执行此操作。
我已经尝试了各种方法,目前最接近的是:
this.contentMouseX and this.contentMouseY
这给了我当前阶段的坐标,这很好,然后我添加了:
NativeApplication.nativeApplication.activeWindow.x and activeWindow.y
这很接近,但这没有考虑应用程序标题栏。
我确信一定有一种更简单、更直接的方法来做到这一点,任何人都可以提供建议,因为我在谷歌上找不到它吗?
我尝试过 localToGlobal ,它不起作用,似乎“全局”意味着在应用程序内,而不是屏幕上的全局,这对我来说没有用。 这是一个显示失败的示例......
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.core.Application;
private function click(evt:MouseEvent):void
{
var pt:Point = new Point( this.contentMouseX, this.contentMouseY );
var global:Point = Application.application.localToGlobal( pt );
trace( "local_x: " + pt.x + " x " + pt.y );
trace( "global_x: " + global.x + " x " + global.y );
}
]]>
</mx:Script>
<mx:HBox horizontalAlign="center" width="100%">
<mx:Button id="butt" label="Click" click="click(event)" />
</mx:HBox>
</mx:WindowedApplication>
I am trying to obtain the actual mouse co-ordinates on the screen so I can create a Native Window at that position but I dont seem to be able to find the right way to do this correctly.
I have tried various things, the closest thing I have at the moment is:
this.contentMouseX and this.contentMouseY
This gives me the coords on the current stage which is fine, then I add to that the:
NativeApplication.nativeApplication.activeWindow.x and activeWindow.y
Which is close, but this doesnt take into account the application title bar.
There must be an easier and more straightforward way of doing this I am sure, can anyone give advice cos I fail to find it on google?
I have tried localToGlobal which doesnt work, it seems that 'global' means within the application and not global to the screen which is of no use to me. Here is an example that shows the failure...
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.core.Application;
private function click(evt:MouseEvent):void
{
var pt:Point = new Point( this.contentMouseX, this.contentMouseY );
var global:Point = Application.application.localToGlobal( pt );
trace( "local_x: " + pt.x + " x " + pt.y );
trace( "global_x: " + global.x + " x " + global.y );
}
]]>
</mx:Script>
<mx:HBox horizontalAlign="center" width="100%">
<mx:Button id="butt" label="Click" click="click(event)" />
</mx:HBox>
</mx:WindowedApplication>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
错误启动后...抱歉...
您可以使用 stage.nativeWindow.globalToScreen - 这将满足您的需要。
就窗口的位置而言(为了完整性) - 您还可以查看 stage.nativeWindow.x 和 stage.nativeWindow.y --- 这将为您提供应用程序在桌面上的位置 - 从那里 - 您可以定位相对于那个点。
After a false start... Sorry about that...
You can use stage.nativeWindow.globalToScreen - this will do what you need.
In terms of position of the window (for completeness) - you can also look into stage.nativeWindow.x and stage.nativeWindow.y --- this will give you the position for the application on the desktop - from there - you can position relative to that point.
这是否有效:
Does this work: