MovieClip._y Property | Flash 4 |
vertical location of a clip or movie, in pixels | read/write |
The floating-point _y property always indicates the vertical position of mc's registration point, but it is measured relative to one of three possible coordinate spaces:
If mc resides on the main timeline, _y is measured relative to the Stage's top edge. For example, a _y of 20 indicates that the registration point of mc is 20 pixels below the Stage's top edge; -20 indicates 20 pixels above.
If mc resides on another movie clip instance's timeline, _y is measured relative to the registration point of that parent instance. For example, a _y of 20 indicates that the registration point of mc is 20 pixels below its parent instance's registration point; -20 indicates 20 pixels above.
If mc is the main movie, _y is the vertical offset of the entire .swf document, relative to the Stage's top edge. For example, a _y of 200 indicates that the contents of the Stage are offset 200 pixels below their author-time position; -200 indicates 200 pixels above.
The _y property (along with all vertical coordinates in Flash) increases downward and decreases upward�the opposite of the Cartesian coordinate system. Fractional _y values are approximated in Flash with antialiasing (blurring). Flash's basic unit of measure is a twentieth of a pixel (a "twip"), so the shortest distance a clip can be moved vertically is .05 pixels. Smaller increments are ignored:
trace(ball_mc._y); // Displays: 0 ball_mc._y += .01; trace(ball_mc._y); // Still displays 0. The assignment had no effect.
If mc 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 mc's parent is scaled by 200% and rotated 90 degrees clockwise, _y will increase toward the left rather than downward, and a single unit of _y will actually be 2 pixels instead of 1.
Because switching between instance and main movie coordinate spaces can be cumbersome, the MovieClip object provides the localToGlobal( ) and globalToLocal( ) methods for performing coordinate-space transformations.
The following onEnterFrame( ) handler causes ball_mc to move down 5 pixels with each passing frame (assuming that its coordinate space hasn't been altered by transformations to its parent):
ball_mc.onEnterFrame = function () { this._y += 5; }
MovieClip.globalToLocal( ), MovieClip.localToGlobal( ), MovieClip._x