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

<!-- /* 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;} -->

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

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

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

Content 的坐标原点不一定是在组件的原点,而是在组件的 content 的左上角。因此如果在 comp1 中添加了 comp2 ,而且 comp2 x y 都是固定的,那么 comp2 的左上角的 content 坐标在 comp1 content 中是不会变的,但是 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>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值