AS3 localToGlobalglobalToLocal方法的总结

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AS3 localToGlobalglobalToLocal方法的总结相关的知识,希望对你有一定的参考价值。

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


  原文:http://bbs.9ria.com/thread-100884-1-3.html




以上是关于AS3 localToGlobalglobalToLocal方法的总结的主要内容,如果未能解决你的问题,请参考以下文章

ActionScript 3 AS3:使用SWFObject2和AS3传递变量

AS3 - 抽象类

AS3 转 Java

AS3:如何在 AS3 类中有效地存储平铺地图编辑器的数据

ActionScript 3 AS3 getURL / navigateToURL(如何在AS3中创建可点击链接)

AS3查询点击功能