| TextField._x Property | Flash 6 |
| horizontal location of the text field, in pixels | read/write |
The floating-point _x property indicates the horizontal position of theField's left border. It is measured relative to one of two possible coordinate spaces:
If theField resides on the main timeline, _x is measured relative to the Stage's left edge. For example, an _x of 20 indicates that theField's left border is 20 pixels to the right of the Stage's left edge; -20 indicates it is 20 pixels to the left.
If theField resides on a movie clip instance's timeline, _x is measured relative to the registration point of that parent instance. For example, an _x of 20 indicates that theField's left border is 20 pixels to the right of its parent instance's registration point; -20 indicates 20 pixels to the left.
The _x property (along with all horizontal coordinates in Flash) increases to the right and decreases to the left. Fractional _x values are approximated in Flash with antialiasing (blurring).
If theField is contained by an instance that is scaled and/or rotated, the coordinate space it inhabits is also scaled and/or rotated. For example, if theField's parent is scaled by 200% and rotated 90 degrees clockwise, _x increases in the downward direction, rather than to the right, and a single unit of _x is 2 pixels instead of 1.
The following example uses the _x property to align one field to another (they share the same x-coordinate, so they are aligned along the same vertical line):
// Make the first field
this.createTextField("firstName_txt", 1, 250, 0, 200, 20);
firstName_txt.border = true;
firstName_txt.type = "input";
// Make the second field
this.createTextField("lastName_txt", 2, 0, 0, 200, 20);
lastName_txt.border = true;
lastName_txt.type = "input";
// Align the second field
lastName_txt._x = firstName_txt._x;
lastName_txt._y = firstName_txt._y + firstName_txt._height + 10;
The following example adds to all text fields a slideTo( ) method that moves a text field left or right to some destination at a given speed:
// Method to start the slide interval
TextField.prototype.slideTo = function (xPos, pixelsPerSec) {
var moveAmount = pixelsPerSec/20;
if (xPos < 0) {
moveAmount = -moveAmount;
}
this.slideInterval = setInterval(this, "slide", 50, moveAmount, xPos);
}
// Method to move the text field
TextField.prototype.slide = function (moveAmount, xPos) {
this._x += moveAmount;
if (Math.abs(this._x - xPos) < 1) {
clearInterval(this.slideInterval);
}
updateAfterEvent();
}
// Make the field
this.createTextField("theField_txt", 1, 0, 0, 200, 20);
theField_txt.border = true;
theField_txt.text = "Watch me go for a ride!";
// Slide it to 500 at speed 100px/second
theField_txt.slideTo(500, 100);
MovieClip.globalToLocal( ), MovieClip.localToGlobal( ), TextField._y