Parameter

Hi all,
I am trying to make 2buttons to only move horizontally by using this action scripts:
var speed = 2;

pink.moveToMouse = function() {
this._x += (targetX-this._x)/speed;
};
pink.onMouseMove = function() {
targetX = _xmouse;
this.onEnterFrame = this.moveToMouse;
}

pink2.moveToMouse = function() {
this._x += (targetX+20-this._x)/3;
};
pink2.onMouseMove = function() {
targetX = _xmouse;
this.onEnterFrame = this.moveToMouse;
}

This action scripts works fine for me; however, I want to have a thick line right behind the buttons and I would like to make the buttons to move around until the mouse is on that thick line. This is the part I am stucked at, and I hope there is someone who might help me on this. Thanks a lot!!!

Happy New Year!!!

the thick line should be a button or a movieclip. if a button (or movieclip using button actions) you would want to use onRollOver/onDragOver and onRollOut/onDragOut for the mouse being over it, otherwise hitTest.

but basically, you test for when the mouse is over the thick line, and when it is,

delete pink.onEnterFrame
delete pink2.onEnterFrame

but first you have to take the this.onEnterFrame = this.moveToMouse in the mouse move, otherwise it will re-assign the onEnterFrame everytime you move the mouse which you dont want. But this will delete the frame movement function associated witht the enterframe stopping the movement. Target can still be calced on mouseMove, but that doesnt matter since its not moving the clip when your mouse goes off the thick line. To re-instate the movement, simply reset the onEnterFrame:

pink.onEnterFrame = pink.moveToMouse;
pink2onEnterFrame = pink2.moveToMouse;

so basically the code should look something like


pink.moveToMouse = function() {
	this._x += (targetX-this._x)/speed;
};
pink.onMouseMove = function() {
	targetX = _xmouse;
}
pink.onEnterFrame = pink.moveToMouse;

pink2.moveToMouse = function() {
	this._x += (targetX+20-this._x)/3;
};
pink2.onMouseMove = function() {
	targetX = _xmouse;
}
pink2.onEnterFrame = pink2.moveToMouse;

thickLine.onRollOver = thickLine.onDragOver = function(){
	delete pink.onEnterFrame
	delete pink2.onEnterFrame
}
thickLine.onRollOut = thickLine.onDragOut = function(){
	pink.onEnterFrame = pink.moveToMouse 
	pink2.onEnterFrame = pink2.moveToMouse 
}
thickLine.useHandCursor = false;

Thank you so much for replying my question, Senocular! I had a tough time figuring out how to do it myself. I am slowing getting hand on actionscript. Anyway, I still have a question on the instruction that you gave me. When you told me to make the thickLine as a button, and use onRollOver/onDragOver and onRollOut/onDragOut for the mouse being over it, otherwise hitTest. Do you mean to put the actionscript below in the button action??? Thank you so much for you help!!!

thickLine.onRollOver = thickLine.onDragOver = function(){
delete pink.onEnterFrame
delete pink2.onEnterFrame
}
thickLine.onRollOut = thickLine.onDragOut = function(){
pink.onEnterFrame = pink.moveToMouse
pink2.onEnterFrame = pink2.moveToMouse
}
thickLine.useHandCursor = false;

no that script is in the frame and references the ‘thickline’ clip. Just give the thickline the instance name ‘thickline’ and it should work