Changing Flex registration point from upper left corner to center
I need help with Flex. I want to learn how you can change the registration point for the C开发者_高级运维anvas. I want to make a zoom of this component, but the point registration in the upper left corner! How do I move to the center?
There are two solutions:
- Place your Canvas in a container object and center it.
- Leave the registration point as it is and when zooming, change the x and y coordinates to the left/top.
There might be a "proper" solution though.
Hope it helps, Rob
I'm not sure how it's going to help to 'center' the registration point, but whatever. This is how you do it:
Flex 3
<mx:Canvas clipContent="false">
<mx:Box width="400" height="400" x="-200" y="-200" backgroundColor="#000000" />
</mx:Canvas>
Flex 4
<s:Group clipAndEnableScrolling="false">
<s:BorderContainer width="400" height="400" x="-200" y="-200" backgroundColor="#000000" />
</s:Group>
But however, there are other problems, like if I want to center the canvas/group, it won't work properly if you use vertical/horizontalCenter because the content within it is off. Personally, I think this workaround is idiotic if you just want to zoom in. It's a fairly simple operation. If you need it to be centered while it's zooming in, you can always change the x/y position of whatever you're zooming into. The calculation is fairly simple to find the center of your components:
var center:Point = new Point(component.x + component.width/2, component.y + component.height/2);
精彩评论