Should be simple... but it is NOT!

I have written this very simple code that should work, but it won’t! Here is the deal. I have 2 boxes. 1 red and one blue. They are both MC. Now when you roll over the red box, the blue box should begin to start to follow your mouse. When you roll out of the red box, the blue box will stop following you. Everything works, but the box still follow even after rollOut. Please help. Here is what I did…

on the red box…

on (rollOver){
_root.follow = 1;
}

on (rollOut){
_root.follow = 0;
}


on the blue box....

onClipEvent(enterFrame){
if (_root.follow == 1){
startDrag(_root.dragger, true, 200, 200, 600, 200);
}
if (_root.follow == 0){
stopDrag();
}
}

why don’t you do this instead…on the movieClip that you want to follow put this code:


onClipEvent(enterFrame){
     if(_root._ymouse >= MaxYValue && _root._ymouse <= MinYValue){
          if(_root._xmouse >= MaxXValue && _root._xmouse <= MinXValue){
                this._x = _root._xmouse
                this._y = _root._ymouse
          } 
     }
}

Something like that should work. Just change the Max and Min X and Y values to the correct numbers…

you’re right about the code though. It certainly looks like it should work… and you say it does, but doesn’t stop working. which is more glitchy than signs of incorrect programming.

just for ****s and giggles, check out your whole movie to make sure that you do not have two movie clips with the same instance name. I often encounter problems like that when I double up on names.

That isn’t the problem at all.

See, the clip activates on rollOver of the red bar. Now, the problem with this is that the blue box moves to your mouse cursor.

You can’t rollOut of your red bar since the blue box is overlapping it.

I will try and fix it.

Ok, I think I came up with something that will work.

Give your red bar the instance name “redBar” (no quotes).

Remove all actionscript from the actions panel for that red bar.

Now open the actions panel for the blue box.

Apply these actions and these actions only to the blue box.

onClipEvent (enterFrame) {
	getlimits = _root.redBar.getBounds(_root);
	if (_root._xmouse>=getlimits.xMin && _root._xmouse<=getlimits.xMax && _root._ymouse>=getlimits.yMin && _root._ymouse<=getlimits.yMax) {
		this._x = _root._xmouse;
		this._y = 200;
	}
}

Give it a whirl… let me know how it goes :slight_smile:

OMG you did it beta. I have been working on this for like a week and a half, but noooo! And you guys come along and get it worked out in one day. This really pisses me off, but ironically makes me happy at the same time. Thanks a bunch fellas.

No problem. You will get more and more used to AS the more you use it.

Practice makes perfect :slight_smile: