2

这是我的示例代码

  <canvas id="myCanvas" x="200" y="200" height="300" width="500"  mouseOver="onOver" />
private function onOver(event:MouseEvent):void
{
trace(mouseX,mouseY);
}

它给了我对我的应用程序 MouseX 和 MouseY 的尊重,但我想尊重我的 Canvas。请帮助我任何人

4

2 回答 2

3

试试这个可能对你有帮助

  <?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.butt.x, this.butt.y );
 var global:Point = Application.application.localToGlobal( pt );

trace( "local_x: " + pt.x + " x " + pt.y );
 trace( "global_x: " + global.x + " x " + global.y );

var p:Point = stage.nativeWindow.globalToScreen(new Point(this.butt.x, this.butt.y));

 trace(p.x + " x " + p.y);
 var na:NativeWindow = new NativeWindow(new NativeWindowInitOptions());
  na.visible = true;
 na.width = 100;
  na.height = 100;
 na.x = p.x;
 na.y = p.y;
  na.activate();

}
]]>
</mx:Script>


<mx:Button x="10" y="10" id="butt" label="Click" click="click(event)" />

 </mx:WindowedApplication>
于 2012-04-26T07:16:51.077 回答
0

尝试以下跟踪: -

trace(event.target.mouseX);
trace(event.target.mouseY);
于 2012-04-26T09:55:34.153 回答