PDA

View Full Version : back and forth movement- why is it jiggling?


daveclark5
04-04-2002, 11:12 PM
I have created a movieclip called MovieBar that is made of buttons. I wanted to make it move left and right depending on the cursor, so this is the code I have assigned:

onClipEvent (enterFrame) {
_parent.mousePOSx = _xmouse; // find the mouses X position
_parent.diff = (_parent.horizontal)*-1; // find the center position
_parent.mousePOSxADJ = _xmouse-_parent.diff; // adjust from center position

// Determine what direction the nav will move.
if (_parent.mousePOSxADJ>0) { // if you're on the right, move the bar right
_parent.MovieBar._x = _parent.MovieBar._x+3;
} else if (_parent.mousePOSxADJ<0) { // if you're on the left, move the bar left
_parent.MovieBar._x = _parent.MovieBar._x-3;
}
}

There are a couple of issues. First, when the mouse is not moving and the "midpoint" is reached, the bar jiggles back and forth, rather than stopping. How can I eliminate this?

Secondly, I'd like to have the midpoint of the stage determine left or right, rather than the midpoint of the bar. What do I need to change?

Finally, I wanted the bar to stop on rollover, so I added an on(rollOver) stop to each of the buttons inside the MC, but it had no effect. Sorry this is so long, but can anyone help? Thanks.

Dave

Jesse
04-05-2002, 01:00 AM
onClipEvent (enterFrame) {
if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
// nothing
} else {
_parent.mousePOSx = _xmouse;
// find the mouses X position
_parent.diff = (_parent.horizontal)*-1;
// find the center position
_parent.mousePOSxADJ = _xmouse-_parent.diff;
// adjust from center position
// Determine what direction the nav will move.
if (Math.abs(this._x-_root._xmouse)<2) {
// nothing
} else if (_parent.mousePOSxADJ>0) {
// if you're on the right, move the bar right
_parent.MovieBar._x = _parent.MovieBar._x+3;
} else if (_parent.mousePOSxADJ<0) {
// if you're on the left, move the bar left
_parent.MovieBar._x = _parent.MovieBar._x-3;
}
}
}
To make it work relative to the stage mid point you'd have to set the stage midpoint (manually at edit-time) as a variable.
Also note that _xmouse returns a relative value, so if you want the _xmouse of the mouse in relation to the stage you need to use _root._xmouse as I have in some points. As you requested it stops when the mouse hits it. If it contained of lots of little boxes with spaces in between you could move your mose in the spaces and cause it to scroll, but as soon as it touches a hard block of color, or a line, it will stop.

pixelwit
04-05-2002, 01:35 AM
You can probably get rid of the jiggle by changing to these lines of code: if (_parent.mousePOSxADJ>4) {
_parent.MovieBar._x += 3;
} else if (_parent.mousePOSxADJ<-4) {
_parent.MovieBar._x -= 3;
}Jesse's answer is better but this might help you understand why it jiggled in the first place.

Hope it helps,

-PiXELWiT
http://www.pixelwit.com

Just a note: The new "as" tag seems to throw in an extra "& gt" every now and then rather than a ">" symbol. if (_parent.mousePOSxADJ>4) {
_parent.MovieBar._x += 3;
} else if (_parent.mousePOSxADJ<-4) {
_parent.MovieBar._x -= 3;
}

Jesse
04-05-2002, 01:40 AM
Hmm that's interesting:
< > test
< > test hmm so it does. I'll write WAWAWOOM and see if they know why.