views:

881

answers:

2

Hi,

How can I extend components like buttons to use x and y value as the center of the component, not the top left?

Thanks,

Jean

A: 

Well, you could write a translator function that takes a control, x, and y, and gives back the center Point:

Xc = (Control.x + (Control.width / 2))
Yc = (Control.y + (Control.height / 2))
return new Point(Xc,Yc)

Then just use your translator to set the position anytime you would otherwise use x and y.

echo
yes, this is a possibility but I am looking into making custom components and I don't see how that would fit in the position process of an UIComponent ( should have made a clearer question).
Jean Fabre
A: 

It's pretty easy in Flex 4 :). They have a transformAround method in the UIComponent, that allows you to transform the position/scale/rotation of a component around any arbitrary pivot. So you could do this:


override public function set x(value:Number):void
{
    var pivot:Vector3D = new Vector3D(this.width/2, this.height/2, 0);
    var translation:Vector3D = new Vector3D(value, this.y, this.z);
    transformAround(pivot, null /* scale vector */, null /* rotation vector */, translation);
}

You could customize/optimize that, but that's the jist :).

If you're using Flex 3, then I'd look into how they did that. It's pretty hardcore, lots of Matrix/Matrix3D stuff.

viatropos
yes using flex3, but not for long, so your option is good, thanks.
Jean Fabre