`
传说の黄花菜
  • 浏览: 200447 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

使用Flex坐标系统及转换

    博客分类:
  • Flex
阅读更多

 

 

 flash和flex针对不同的目的,提供了3种不同的坐标系。

          全局的就是(stage级别的)

          本地坐标系(组件级别的)

          内容坐标系(相对于本地坐标系说的)

    这些坐标系的点是可以转换的,并且有相应的方法,看来adobe想得挺周到。我们一个一个的说一下:

    全局

           这个坐标系的原点在整个flash舞台的左上角,MouseEvent实例的stageX,stageY就是这个坐标系中的值。

    本地

        坐标原点是相对的组件的左上角,MouseEvent中的localX,localY就是相对这个坐标系说的。

    内容

        这个东西比较抽象了UIComponent类实例的contentMouseX  和 contentMouseY 就是了,这个主要针对有滚动条的组件说的,有滚动条了,内容肯定不少,内容所占的区域的坐标就是这个坐标系了。

下面有个官方的图说明了三个坐标系的关系及位置:

 


 

A. Content bounds B. Component bounds C. Stage bounds

 

 

坐标转换还有现成的方法:

contentMouseX

返回mouse的内容坐标x值

contentMouseY

返回mouse的内容坐标Y值

contentToGlobal   

将内容坐标转换成全局坐标

contentToLocal 

将内容坐标转换成内容坐标

globalToContent   

将全局的转成内容坐标

globalToLocal 

全局的转成本地的

localToContent

本地到内容坐标

localToGlobal 

本地到全局坐标

下面是一个小例子:

  1. <?xml version= "1.0" ?>  
  2. <!-- containers\intro\MousePosition.mxml -->  
  3. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"   
  4.     backgroundColor="white" >  
  5.      
  6.     <mx:Script>  
  7.         <!--[CDATA[  
  8.           import mx.controls.Alert;  
  9.           // Handle the mouseDown event generated   
  10.           // by clicking in the application.   
  11.           private  function handleMouseDown( event :MouseEvent): void  {  
  12.                  
  13.             // Convert the mouse position to global coordinates.   
  14.             // The localX and localY properties of the mouse event contain   
  15.             // the coordinates at which the event occurred relative to the   
  16.             // event target, typically one of the   
  17.             // colored internal Canvas controls.   
  18.             // A production version of this example could use the stageX   
  19.             // and stageY properties, which use the global coordinates,   
  20.             // and avoid this step.   
  21.             // This example uses the localX and localY properties only to   
  22.             // illustrate conversion between different frames of reference.   
  23.             var pt:Point = new  Point( event .localX,  event .localY);  
  24.             pt = event .target.localToGlobal(pt);  
  25.                  
  26.             // Convert the global coordinates to the content coordinates   
  27.             // inside the outer c1 Canvas control.   
  28.             pt = c1.globalToContent(pt);  
  29.                 
  30.             // Figure out which quadrant was clicked.   
  31.             var whichColor:String = "border area" ;  
  32.                
  33.             if  (pt.x < 150) {  
  34.                 if  (pt.y < 150)  
  35.                     whichColor = "red" ;  
  36.                 else   
  37.                     whichColor = "blue" ;  
  38.             }  
  39.             else  {  
  40.                 if  (pt.y < 150)  
  41.                     whichColor = "green" ;  
  42.                 else   
  43.                     whichColor = "magenta" ;  
  44.             }  
  45.                  
  46.             Alert.show("You clicked on the "  + whichColor);  
  47.           }  
  48.         ]]-->  
  49.     </mx:Script>  
  50.     <!-- Canvas container with four child Canvas containers -->  
  51.     <mx:Canvas id="c1"   
  52.         borderStyle="none"   
  53.         width="300"  height= "300"   
  54.         mouseDown="handleMouseDown(event);" >  
  55.          
  56.         <mx:Canvas  
  57.             width="150"  height= "150"   
  58.             x="0"  y= "0"   
  59.             backgroundColor="red" >  
  60.             <mx:Button label="I'm in Red" />  
  61.         </mx:Canvas>  
  62.         <mx:Canvas  
  63.             width="150"  height= "150"   
  64.             x="150"  y= "0"   
  65.             backgroundColor="green" >  
  66.             <mx:Button label="I'm in Green" />  
  67.         </mx:Canvas>  
  68.         <mx:Canvas  
  69.             width="150"  height= "150"   
  70.             x="0"  y= "150"   
  71.             backgroundColor="blue" >  
  72.             <mx:Button label="I'm in Blue" />  
  73.         </mx:Canvas>  
  74.         <mx:Canvas  
  75.             width="150"  height= "150"   
  76.             x="150"  y= "150"   
  77.             backgroundColor="magenta" >  
  78.             <mx:Button label="I'm in Magenta" />  
  79.         </mx:Canvas>  
  80.     </mx:Canvas>  
  81. </mx:Application> 

执行效果图如下:


 

  • 大小: 6.3 KB
  • 大小: 7.8 KB
分享到:
评论
1 楼 tianbianfei 2012-04-19  

相关推荐

    FLEX 实现坐标系转换

    flex实现坐标转换 界面化的网页设计,实现转换坐标,简单

    flex arcengine开发坐标转换

    flex gis开发坐标转换 源代码

    Flex客户端自定义投影坐标转换

    本范例是将wgs1984坐标 转换为Xian_1980_3_DEGREE_GK_Zone_40(EPSG:2364)

    FLEX 等距离偏移一条折线

    将一条折线,等距离偏移一定距离。 把屏幕坐标转换为GIS坐标,可以在地图上偏移折线

    Flash ActionScript 3.0高级动画教程

    屏幕坐标转换等角坐标 IsoUtils类 等角对象 层深排序 等角世界类 3D移动 碰撞检测 使用外部图形 等角地图 总结 第四章 寻路 3 寻路基础 A-star A_star运算法则 代价计算 图解运算过程 代码实现 常见的Astar估价公式 ...

    MapGIS IGServer Flex 问题集锦

    怎样使用 MapGIS IGServer Flex 功能组件 .................................................... 10 第 4 问 怎样更新 MapGIS IGServer Flex 功能组件 .................................................... 13 ...

    太乐地图下载器V4.6破解+步骤

    支持对自有坐标数据进行纠偏或加偏处理,同时支持将坐标数据转换为Kml或Excel格式 13.影像坐标系转换。支持任意投影之间的影像坐标系转换,如将具备谷歌投影的地图转为WGS84、xian80、china2000等 14.B/S C/S多种...

    GIS画圆的as源码

    支持投影坐标系的转换,基于地理空间画圆。

    太乐地图下载器v5.0.5(16年最新)

    BS/CS/Mobile离线访问、离线站点自动构建、国家基本比例尺地形图分幅下载、大图智能分块、地标自动绘制、坐标系转换(CGCS2000/WGS84/Xianan80/Beijing54等等)、专业纠偏(WGS84/GCJ-02/BD-09互转)等

    太乐地图下载器V5.0.2

    BS/CS/Mobile离线访问、离线站点自动构建、国家基本比例尺地形图分幅下载、大图智能分块、地标自动绘制、坐标系转换(CGCS2000/WGS84/Xianan80/Beijing54等等)、专业纠偏(WGS84/GCJ-02/BD-09互转)等

    太乐地图下载

    BS/CS/Mobile离线访问、离线站点自动构建、国家基本比例尺地形图分幅下载、大图智能分块、地标自动绘制、坐标系转换(CGCS2000/WGS84/Xianan80/Beijing54等等)、专业纠偏(WGS84/GCJ-02/BD-09互转)等

    ActionScript开发技术大全

    15.1.4极坐标转换 319 15.1.5坐标计算 320 15.1.6坐标缩放 320 15.2矩形对象 321 15.2.1创建Rectangle对象 321 15.2.2确定矩形位置 321 15.2.3调整矩形 322 15.2.4位置关系判定 324 15.3矩阵对象 325 15.3.1初始化...

    flexible.js实现移动端rem适配方案

    设备独立像素:也称为密度无关像素,可以认为是计算机坐标系统中的一个点,这个点代表一个可以由程序使用的虚拟像素(比如说CSS像素),然后由相关系统转换为物理像素。 设备像素比:简称为dpr,其定义了物理像素和...

    太乐地图下载器V5.2.7全数据全功能版本(2018最新)

    地图随意变色、BS/CS/Mobile离线访问、离线站点自动构建、国家基本比例尺地形图分幅下载、大图智能分块、地标自动绘制、坐标系转换(CGCS2000/WGS84/Xianan80/Beijing54等)、专业纠偏(WGS84/GCJ-02/BD-09互转)等

    太乐地图下载器V5.3.6(2019全地图全功能).rar

    地图随意变色、BS/CS/Mobile离线访问、离线站点自动构建、国家基本比例尺地形图分幅下载、大图智能分块、地标自动绘制、坐标系转换(CGCS2000/WGS84/Xianan80/Beijing54等)、专业纠偏(WGS84/GCJ-02/BD-09互转)等

    css入门笔记

    独立于任何网页位置处,声明一个样式文件(.css为后缀),在文件中声明样式,在使用的网页中引入.css文件。 使用步骤: 1.创建样式表文件(.css) 2.在样式文件中编写样式规则 3.在网页中对样式文件进行引入 &lt...

    emWin5用户手册(中文)

    1.9 屏幕和坐标 ...............................................................................................27 1.10 如何将显示器连接到微控制器 ..........................................................

Global site tag (gtag.js) - Google Analytics