Jacqueline,
[quoted text, click to view] > I would like a movie clip to glide (not jump) to a specific
> x position based on a button click (move right or left)...
> can anyone point me to a tutorial?
A jump would be a quick one shot deal, like this:
myButtonInstance.onRelease = function() {
_root.pathToMovieClip.movieClipInstance._x = 500;
}
In order to perform a glide, you need animation, which can be summed up
as changing position (and/or other qualities) over time. There are two
basic ways to achieve this in ActionScript. Either use the
MovieClip.onEnterFrame event handler, or the setInterval() function. Let's
check out onEnterFrame to begin with.
This will be just like assigning a function to the onRelease event
handler of our button instance above. All MovieClip instances inherit
onEnterFrame (the full list is seen in the "MovieClip class" entry of the
ActionScript Language Reference), so we simply tell this movie clip what to
do every time it enters a frame. In this case, we want it to increment its
_x property by 2.
myButtonInstance.onRelease = function() {
_root.pathToMovieClip.movieClipInstance.onEnterFrame = function() {
this._x += 2;
};
}
Of course, we could have it move to the right *and* up by incrementing
_x and decrementing _y.
myButtonInstance.onRelease = function() {
_root.pathToMovieClip.movieClipInstance.onEnterFrame = function() {
this._x += 2;
this._y -= 5;
};
}
The word "this" in this context refers to the movie clip itself, since
the function assigned to its onEnterFrame event handler is scoped to the
movie clip in question. It makes for a quick, neat way to refer to the clip
and adjust any number of properties, including _alpha, _rotation, and so on.
The nice thing about assigning event handler functions in this manner
(as opposed to using on() or onClipEvent()) is that we can kill the handlers
when they're no longer needed.
Say we want the movie clip to move from where it is to the left, and
stop when it's 50 pixels from the left edge of the screen.
myButtonInstance.onRelease = function() {
_root.pathToMovieClip.movieClipInstance.onEnterFrame = function() {
if (this._x > 50) {
this._x--;
} else {
delete this.onEnterFrame;
}
};
}
The -- operator is the same as saying -= 1, also the same as this._x =
this._x -1.
Does that make sense? Write back if you still have questions.
David
stiller (at) quip (dot) net
"Luck is the residue of good design."