AS3 localToGlobal, globalToLocal 방법의 총 결

3070 단어 AS3
원문:http://bbs.9ria.com/thread-100884-1-3.html
(1).localToGlobal (point)   point 를 (1) 내부 로 보고 이 point 가 stage 에 해당 하 는 좌 표를 계산 합 니 다.
(2).globalToLocal (point)   point 는 전역 좌표 로 이 point 가 (2) 에 해당 하 는 좌 표를 계산 합 니 다.
package
{
        import flash.display.Sprite;
        import flash.display.StageAlign;
        import flash.display.StageScaleMode;
        import flash.events.Event;
        import flash.geom.Point;
        
        
        public class testZuoBiaoZhuanHuan extends Sprite
        {
                private var s1 : Sprite = new Sprite();
                private var s2 : Sprite = new Sprite();
                private var s3 : Sprite = new Sprite();
                
                private var pointTemp : Point = new Point(10,10);
                private var pointResult : Point;

                
                
                public function testZuoBiaoZhuanHuan()
                {
                        this.addEventListener(Event.ADDED_TO_STAGE,onAddToStage);
                }
        
                private function onAddToStage(e : Event):void
                {
                        stage.scaleMode = StageScaleMode.NO_SCALE;
                        stage.align = StageAlign.BOTTOM;
                        
                        addChild(s1);
                        s1.graphics.beginFill(0xff0000);
                        s1.graphics.drawRect(0,0,80,80);
                        s1.graphics.endFill();
                        
                        s1.addChild(s2);
                        s2.x = 10;
                        s2.y = 10;
                        s2.graphics.beginFill(0x00ff00);
                        s2.graphics.drawRect(0,0,60,60);
                        s2.graphics.endFill();
                        
                        s2.addChild(s3);
                        s3.x = 10;
                        s3.y = 10;
                        s3.graphics.beginFill(0x0000ff);
                        s3.graphics.drawRect(0,0,40,40);
                        s3.graphics.endFill();
                        
                        pointResult = s1.localToGlobal(new Point(10,10));
                        trace(pointResult.x , pointResult.y);
                        
                        pointResult = s2.localToGlobal(new Point(20,20));
                        trace(pointResult.x , pointResult.y);
                        
                        pointResult = s3.localToGlobal(new Point(30,30));
                        trace(pointResult.x , pointResult.y);
                        
                        pointResult = s1.globalToLocal(pointTemp);
                        trace(pointResult.x , pointResult.y);
                        
                        pointResult = s2.globalToLocal(pointTemp);
                        trace(pointResult.x , pointResult.

                        pointResult = s3.globalToLocal(pointTemp);
                        trace(pointResult.x , pointResult.y);
                                
                }
                
        }
}

좋은 웹페이지 즐겨찾기