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)); }

  

以下代码创建一个 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]

  

posted @ 2013-01-31 12:39  ChangeLi  阅读(250)  评论(0编辑  收藏  举报