Flash-flex coordinate system and its transformation

Source: Internet
Author: User
Tags relative

Flash and flex provide 3 different coordinate systems for different purposes.

The overall situation is (stage level)

Local coordinate system (component level)

The content coordinate system (as opposed to the local coordinate system)

The points of these coordinate systems can be converted, and there are corresponding methods, and it seems that Adobe is very thoughtful. Let's say one at a moment:

Global

The origin of this coordinate system is in the upper-left corner of the entire flash stage, and the stagex,stagey of the MouseEvent instance is the value in this coordinate system.

Local

The coordinate origin is the upper-left corner of the relative component, and the localx,localy in the MouseEvent is said to be relative to the coordinate system.

Content

This thing is more abstract UIComponent class instance of the contentmousex and contentMouseY is, this is mainly for the components of the scroll bar, there is a scroll bar, the content is certainly a lot, the content of the area of the coordinates is this coordinate system.

Here's an official diagram that illustrates the relationship and location of three coordinate systems:

. net/art/20091003/r91tmcxl6zxhy7o.jpg "target=" _blank ">

There are also ready-made methods for coordinate conversion:

contentMouseX

Returns the content coordinate x value of mouse

contentMouseY

Returns the content coordinate Y-value of mouse

contentToGlobal   

Convert content coordinates to global coordinates

contentToLocal 

convert content coordinates to content coordinates

globalToContent   

Turn Global to content coordinates

globalToLocal 

Global turn to Local

localToContent

Local to content coordinates

localToGlobal 

Local to global coordinates

Here is a small example:

  1. <?xml version= "1.0" ?>
  2. <!--Containersintromouseposition.mxml-->
  3. <mx:application xmlns:mx="Http://www.adobe.com/2006/mxml"
  4. backgroundcolor="white">
  5. <mx:Script>
  6. <!--[cdata[
  7. Import Mx.controls.Alert;
  8. //Handle The MouseDown event generated   
  9. //By clicking in the application.   
  10. Private function Handlemousedown (event: mouseevent): void  {  
  11. //Convert the mouse position to global coordinates.   
  12. //The Localx and Localy properties of the mouse event contain   
  13. //The coordinates at which the event occurred relative to the   
  14. //Event target, typically one of the   
  15. //colored internal Canvas controls.   
  16. //A production version of this example could use the Stagex   
  17. //And Stagey properties, which use the global coordinates,   
  18. //And avoid this step.   
  19. //This example uses the Localx and Localy properties   
  20. //Illustrate conversion between different frames of reference.   
  21. var pt:point = New Point (eventlocalx, event. localy);
  22. PT = Event. Target.localtoglobal (PT);
  23. //Convert the global coordinates to the content coordinates   
  24. //Inside the outer C1 Canvas control.   
  25. PT = C1.globaltocontent (PT);
  26. //Figure out which quadrant is clicked.   
  27. var whichcolor:string = "border area";
  28. if (Pt.x <) {
  29. if (Pt.y <)
  30. Whichcolor = "Red";
  31. Else   
  32. Whichcolor = "Blue";
  33. }
  34. Else  {  
  35. if (Pt.y <)
  36. Whichcolor = "green";
  37. Else   
  38. Whichcolor = "Magenta";
  39. }
  40. Alert.show ("You clicked on the" + whichcolor);
  41. }
  42. ]]-->
  43. </mx:Script>
  44. <!--Canvas container with four Canvas containers-->
  45. <mx:canvas id="C1"
  46. borderstyle="None"
  47. Width= " height= "
  48. mousedown="Handlemousedown (event);" >
  49. <mx:canvas
  50. Width= " height= "
  51. x="0" y="0"
  52. backgroundcolor="Red">
  53. <mx:button label="I ' m in Red"/>
  54. </mx:Canvas>
  55. <mx:canvas
  56. Width= " height= "
  57. x= " y=" "0"
  58. backgroundcolor="green">
  59. <mx:button label="I ' m in Green"/>
  60. </mx:Canvas>
  61. <mx:canvas
  62. Width= " height= "
  63. x= "0" y= "
  64. backgroundcolor="Blue">
  65. <mx:button label="I ' m in Blue"/>
  66. </mx:Canvas>
  67. <mx:canvas
  68. Width= " height= "
  69. x= " y= "
  70. backgroundcolor="Magenta">
  71. <mx:button label="I ' m in magenta"/>
  72. </mx:Canvas>
  73. </mx:Canvas>
  74. </mx:Application>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.