您的位置:首页 > 移动开发

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

2009-10-22 22:57 531 查看
<!--
/* 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>

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息