Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

making onDrag lock the mouse in place

Status
Not open for further replies.

Dustman

Programmer
May 7, 2001
320
US
I don't know exactly how to word this.. basically, I have a homemade scroll button. All my scrolling works fine but I have a problem with onRelease because the mouse isn't on the scrollhead movieclip any moore. Is there a way to lock the x value of the mouse itself while dragging?


Go to the Schedule page and drag the yellow scroll head.

-Dustin
Rom 8:28
 
I hate bumping posts but since this is a slow season.. does anybody have an idea on this one?

-Dustin
Rom 8:28
 
If you happen to be using startDrag you can use true to lock the mouse onto the object.

startDrag(yourtargetobject,true);

true will lock the mouse in place to that object.

If you are still having problems post your code you are using for the drag and I will see if I have any other ideas.

-Chad
 
I've tried the true value, however, it only locks the y value. I need it to lock the x and y value. In fact, the true value makes things worse, you cannot even click on the scrollhead again to catch the onRelease.

Test this yourself..

(Schedule link)




The -t version has the lock set to true. To test, click on the yellow scroll head and drag.. when releasing the mouse, make sure its not over the scroll head. To make it stop scrolling, you have to mouse back over the scrollhead and click & release it without moving the mouse.

** NOTE: This site uses Flash 8 specific features, make sure you have the latest flashplayer.

Here is my drag code. My scrollhead is a class and this is the onPress & onRelease function.

Code:
        function onPress() {
		this.startDrag(false, 246.8, this.TopY, 246.8, this.BottomY);
		this.onEnterFrame = function() {
			//   (c-t)/.01(b-t)
			var sp:Number = ((this._y - this.TopY)/(.01 * (this.BottomY - this.TopY)));
			if(sp<=0) {
				sp = 0;
			} else if(sp>=100) {
				sp = 100;
			}
			this.ScrollWin.slidePercent(sp);
			_root._xmouse = this._x;
		}
	}

	function onRelease() {
		this.stopDrag();
		delete this.onEnterFrame;
	}

-Dustin
Rom 8:28
 
Here is some code I just wrote and seems to work ok. The mouse stays over the slider. It seems there is just too much work to turn off the other axis with startDrag. Let me know if this is what you are looking for.
Code:
onClipEvent(mouseDown){
if (this.hitTest(_root._xmouse,_root._ymouse))//test to make sure the mouse is over this
{mousedown = true;// set a variable so you can constantly have a true or false the button is still pressed
}}

onClipEvent(enterFrame){
	if (mousedown) {this._y = _root._ymouse;} } // update the location of this to the root mouse location
	
	onClipEvent (mouseUp) {mousedown = false;}
 
I feel like a moron.. all I needed to do was work on this during the day when I could think straight. In my same class.. I just have to add a onReleaseOutside() function. Works like a charm now. Thanks for the help!

Code:
function onRelease() {
    this.stopDrag();
    delete this.onEnterFrame;
}

function onReleaseOutside() {
    this.onRelease();
}

-Dustin
Rom 8:28
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top