Flex中的local, content, global坐标分析

来源:互联网 发布:软件买卖网 编辑:程序博客网 时间:2024/05/29 18:33

<!-- /* Font Definitions */ @font-face{font-family:宋体;panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-alt:SimSun;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;}@font-face{font-family:"/@宋体";panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal{mso-style-parent:"";margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:inter-ideograph;mso-pagination:none;font-size:10.5pt;mso-bidi-font-size:12.0pt;font-family:"Times New Roman";mso-fareast-font-family:宋体;mso-font-kerning:1.0pt;} /* Page Definitions */ @page{mso-page-border-surround-header:no;mso-page-border-surround-footer:no;}@page Section1{size:612.0pt 792.0pt;margin:72.0pt 90.0pt 72.0pt 90.0pt;mso-header-margin:36.0pt;mso-footer-margin:36.0pt;mso-paper-source:0;}div.Section1{page:Section1;}-->

注意:以下所有globallocal,content坐标都是针对于上面这个组件而言的。

以上面这个组件(组件一, comp1)这例,假如当前这个文档的这一页为舞台,那么这个组件的左上角在该页面的坐标就是该组件的global坐标.

现在假设在组件一中还有一个组件(组件二,comp2),那组件二左上角的坐标则是组件一的contentcontent坐标,表示的是comp2comp1content中的绝对位置。

Content的坐标原点不一定是在组件的原点,而是在组件的content的左上角。因此如果在comp1中添加了comp2,而且comp2xy都是固定的,那么comp2的左上角的content坐标在comp1content中是不会变的,但是local坐标可能会变。因为local坐标永远是相对于comp1的左上角而言的。

 

 

<?xml version ="1.0" encoding = "utf-8"?>

<mx:Application xmlns:mx = "http://www.adobe.com/2006/mxml"layout = "absolute">

    <mx:Script>

        <![CDATA[

            import mx.containers.Canvas;

 

            private function showSupportingArea():void

            {

                support.height=200;

                var point:Point=new Point();

//                point.x = lbl.x;

//                point.y = lbl.y;

//                point =lbl.localToContent(point);

//                trace(point.x);trace(point.y);

//               point=lbl.contentToGlobal(point);

//                trace(point.x);

//                trace(point.y);

                point=lbl.localToGlobal(point);

                trace(point.x);

                trace(point.y);

//                point=lbl.globalToLocal(point);

//                trace(point.x);

//                trace(point.y);

               point=canvas.globalToContent(point);

                trace(point.x);

                trace(point.y);

//               point=canvas.globalToLocal(point);

//                trace(point.x);

//                trace(point.y);

            }

        ]]>

    </mx:Script>

    <mx:Button click = "showSupportingArea()" label = "Test"/>

    <mx:VDividedBox id = "vbox" y = "80" height = "500" width ="100%">

        <mx:Canvas id = "canvas" backgroundColor= "blue" width = "100%" height = "50%">

            <mx:Label text = "Hello" id = "lbl" x = "80" y = "300"/>

        </mx:Canvas>

        <mx:Canvas id = "support"backgroundColor = "red" width = "100%" height = "0"/>

    </mx:VDividedBox>

</mx:Application>

 

原创粉丝点击