Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flash 使用AS3查找舞台上的坐标_Flash_Actionscript 3_Coordinates - Fatal编程技术网

Flash 使用AS3查找舞台上的坐标

Flash 使用AS3查找舞台上的坐标,flash,actionscript-3,coordinates,Flash,Actionscript 3,Coordinates,我试图计算出舞台坐标(x,y),这样当点击图片中的对象时,我可以让图例中的对象移动 如果我正确理解了你的问题,谢谢你。。。 …一种解决方案是向stage添加MouseEvent侦听器,然后访问事件的stageX和stageY属性。例如: (很抱歉,我现在工作有点太忙,无法测试此代码,但这样做应该可以奏效。) 当然,您不必将事件侦听器添加到阶段。您可以将其添加到任何相关对象。图片元素的父对象可能是理想的。你可以从任何鼠标事件中获得stageX/stageY 希望能帮助别人, -Kevin使用sta

我试图计算出舞台坐标(x,y),这样当点击图片中的对象时,我可以让图例中的对象移动


如果我正确理解了你的问题,谢谢你。。。 …一种解决方案是向stage添加MouseEvent侦听器,然后访问事件的stageX和stageY属性。例如:

(很抱歉,我现在工作有点太忙,无法测试此代码,但这样做应该可以奏效。)

当然,您不必将事件侦听器添加到阶段。您可以将其添加到任何相关对象。图片元素的父对象可能是理想的。你可以从任何鼠标事件中获得stageX/stageY

希望能帮助别人,
-Kevin

使用
stage.mouseX
stage.mouseY
man、
e.stageX
e.stageY
仅用于
当前目标的坐标。

你是什么意思?您是想计算鼠标点击舞台的坐标,还是舞台上物体的位置,还是想将局部坐标转换为全局坐标?是否想更详细地解释一下这种情况?
stage.addEventListener(MouseEvent.CLICK, handleClick);

private function handleClick( event:MouseEvent ):void {
     var x:int = event.stageX;
     var y:int = event.stageY;

     var whatWasClicked:Object = event.target;

    //do things with x,y depending on what the target is
    //something like
    //if(whatWasClicked is MovieClip){
    //   (whatWasClicked as MovieClip).x = 200;
    //}
}