Table of Contents

TextField._x Property Flash 6

horizontal location of the text field, in pixels read/write
theField._x

Description

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:

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.

Example

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);

See Also

MovieClip.globalToLocal( ), MovieClip.localToGlobal( ), TextField._y


Table of Contents