localToGlobal 本地转换全局
生活随笔
收集整理的這篇文章主要介紹了
localToGlobal 本地转换全局
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
// localToGlobal 本地轉換全局
var square:Sprite = new Sprite(); square.graphics.beginFill(0xFFCC00); square.graphics.drawRect(0, 0, 100, 100); square.x = 100; square.y = 200;addChild(square);square.addEventListener(MouseEvent.CLICK, traceCoordinates)function traceCoordinates(event:MouseEvent):void {var clickPoint:Point = new Point(square.mouseX, square.mouseY);trace("顯示對象坐標:", clickPoint);trace("舞臺坐標:", square.localToGlobal(clickPoint)); }
var square:Sprite = new Sprite(); square.graphics.beginFill(0xFFCC00); square.graphics.drawRect(0, 0, 100, 100); square.x = 100; square.y = 200;addChild(square);square.addEventListener(MouseEvent.CLICK, traceCoordinates)function traceCoordinates(event:MouseEvent):void {var clickPoint:Point = new Point(square.mouseX, square.mouseY);trace("顯示對象坐標:", clickPoint);trace("舞臺坐標:", square.localToGlobal(clickPoint)); }
以下代碼創建一個 Shape 對象,并顯示使用不同點作為參數調用 hitTestPoint() 方法的結果。globalToLocal() 方法將點從 Stage 坐標轉換到該形狀的坐標空間:import flash.display.Shape; import flash.geom.Point;var circle:Shape = new Shape(); circle.graphics.beginFill(0x0000FF); circle.graphics.drawCircle(40, 40, 40); circle.x = 10; addChild(circle);var point1:Point = new Point(0, 0); trace(circle.hitTestPoint(point1.x, point1.y, true)); // false trace(circle.hitTestPoint(point1.x, point1.y, false)); // false trace(circle.globalToLocal(point1)); // [x=-10, y=0]var point2:Point = new Point(10, 1); trace(circle.hitTestPoint(point2.x, point2.y, true)); // false trace(circle.hitTestPoint(point2.x, point2.y, false)); // true trace(circle.globalToLocal(point2)); // [x=0, y=1]var point3:Point = new Point(30, 20); trace(circle.hitTestPoint(point3.x, point3.y, true)); // true trace(circle.hitTestPoint(point3.x, point3.y, false)); // true trace(circle.globalToLocal(point3)); // [x=20, y=20]
轉載于:https://www.cnblogs.com/ChangeTheWorlds/archive/2013/01/31/2886800.html
總結
以上是生活随笔為你收集整理的localToGlobal 本地转换全局的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux命令之感叹号 !
- 下一篇: DOM 节点的创建、删除、替换