Help with movement script:

im using this

onClipEvent (load) {
speed = 5;
onClipEvent (enterFrame) {
if (this.hitTest(_root._xmouse, _root._ymouse)) {
// /////////////
if (_root.hitbar._x>_root._xmouse) {
_root.hitbar._x = _root.hitbar._x-((_root.hitbar._x-_root._xmouse)/speed);
if (_root.hitTest(_root._xmouse, _root._ymouse)) {
if (_root.hitbar._x<_root._xmouse) {
_root.hitbar._x = _root.hitbar._x+((_root._xmouse-this.hitbar._x)/speed);
// /////////////////////////

however I cant get the script to work
Im placing this script on a movie clip, there is a second MC whose instance name is “hitbar” and when the mouse hits this MC it should trigger the first MC to travel along the X axis…

any help?


When you do the hitTest you have put a boolean value:

if(this.hitTest(_root._xmouse, _root._ymouse, true) == true){
 trace("Mouse hit!");


i tried implementing the changes using that, i still cant get it tow work…

how are you using it in the entire script?


post your file so i can have a look at it

i sorta got the script to work, however its “jerky” amd has some undesirbale effects… I would like it to operate much smoother.

Do you want the pink MC follow the mouse when the mouse is over the grey MC? If yes then I think you should take a look at this!

very nice, is there a way( withen the same script) to restrain the pink MC to only move be able to move to a certain x position? I dont want the pink MC to be able to move further than the hitarea box.

thanks so much.

You can use conditional statements again for that. You can compare the _x position and the width of the hit area MC as the borders. I’ll give your file shot tomorrow. I’ll have to take a rest! :slight_smile:

In the meantime try to experiment with it!

word is bond. :beam: