0
votes

Halo...I made a textfield using action script. Here is the code:

var tf:TextField; 

but when i want to put it in some coordinates, the default registration point is in top left of the textfield... How to change it to middle of the textfield.

Thanks.

2

2 Answers

0
votes

If you want to move the registration point, you actually have to move the content, not the point of the container (which is fixed). For this, you have to use the transformation Matrix http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/geom/Matrix.html

In your case, just moving the content without scale, you need to:

tf.transform.matrix = new Matrix(1, 0, 0, 1, leftValue, upValue);

where leftValue and upValue are negative numeric values, equal to half the size of the textfield. Thus, the textfield is moved and the registration point of the container is at the middle of the textfield.

0
votes

Registration point is always at (0,0) when generating content dynamically.

You can either go with matrix transform as @randunel suggests, or simply find the middle of 'tf' and set your coordinate there :

var fieldWidth=tf.textWidth;
tf.x=20+(fieldWidth/2);