PDA

View Full Version : hitTest to drag


tinyk
06-28-2004, 09:00 PM
I'm trying to create a window that has a close button and is draggable, using hitTest and onMouseDown.
I can get it to drag, but i can't get it to stop on the mouseUp.

followMe = function(mc) {
this.onEnterFrame=function() {
mc._x=_xmouse;
mc._y=_ymouse;
}
}
box.onMouseDown=function() {
if(box.drgme.hitTest(_xmouse,_ymouse)){
followMe(box);
}
trace("hit");
}
box.button.onRelease=function() {
box._visible=false;
}

any suggestions?

farafiro
06-29-2004, 09:21 AM
box.onPress=function() {
this.startDrag();
}
box.onRelease=function() {
this.stopDrag();
}

tinyk
06-29-2004, 01:14 PM
Thanks Farafiro! I was trying to do it without startDrag since I have another button inside my movieClip (and you can't have two buttons inside the same movieClip -- or so I thought), but I decided to use the hitTest to act as the button (to close the window), and the startDrag like you suggested, to drag the movieClip.
Thanks again!

farafiro
06-29-2004, 01:33 PM
u can use the startDrag for both

tinyk
06-30-2004, 05:38 PM
basically i have an MC that pops up, containing ten buttons (which load text files and jpgs) and a "close" button to "close" the MC.
I would like the MC to be draggable, but if I set it to startDrag, then the ten buttons become inactive. So I was wondering if there was a way to create a startDrag effect with using hitTest and onMouseDown. (which I can do, but I don't know how to stop the "drag" once I've started.
I have a feeling this doesn't make any sense at all!!

binkyboo
06-30-2004, 08:24 PM
I have no idea if this will work. Obviously it's untested.

Create an onMouseUp event

box.onMouseUp=function() {
if(box.drgme.hitTest(_xmouse,_ymouse)){
dropMe(box);
}
}

now create a function called dropMe


dropMe= function(mc) {
mc._x=_xmouse;
mc._y=_ymouse;
}

farafiro
07-04-2004, 06:34 AM
but if I set it to startDrag, then the ten buttons become inactive. this is strange
can u post a sample fla??

manuelarean
07-05-2004, 01:43 PM
And if you use an if statement with hitTest && onClipEvent (mouseDown)???

I think the problem for your movie is that when you first "start drag" with hit test, your if statement became always true... so you would never "stop drag"

sn3p
07-12-2005, 11:07 PM
[QUOTE="tinyk"]but if I set it to startDrag, then the ten buttons become inactive.[QUOTE]

Got the same problem! I have a mc with 4 buttons in it and use this code to start dragging it:
onClipEvent(load){
startDrag(this, true, 0, _y, Stage.width, _y);
}
When the movie starts it starts dragging the mc (horizontaly, wich it does) and the buttons need to be clickable.. wich won't work untill i use a stopDrag i guess :confused:

I'm trying to make a navigation simular to the intro (language selection) of www.nike.com. Anyone got a clue how to fix this problem?

There's another thread on this subject:
http://www.actionscript.org/forums/showthread.php3?t=69606

tia, sn3p

sn3p
07-12-2005, 11:41 PM
Got rid of the startDrag and used this instead:
onClipEvent (enterFrame) {
this._x = _root._xmouse;
}
Now i got one thing left to fix.. i don't want the mc thats been dragged to move out of the Stage(edges). With startDrag this was no problem.. but with this new solution i'm stuck. What would be the best way to do this?

sn3p