PDA

View Full Version : How to set an draggable area


Xansi
10-16-2002, 10:05 PM
Hello world, here are a question you may answer:
I want to create a draggable MC inside the main stage, but I canīt delimitate the draggable area to the MC, if I click and dragg anywhre on the stage, my MC moves along.
How can I avoid this?

I will apreciate any help you can bring.

-Xansi

toke
10-16-2002, 11:49 PM
ok.. you might want to check these... :D

1. did you give the draggable movie an "instance name"?
2. did you have the stopDrag(); on the draggable movie?

3. post your scripts so I know what you have been up to.

may not help at all :eek:

Xansi
10-17-2002, 03:26 PM
yes, I name it
and yes, I have the stopDrag ()
here is the script:
onClipEvent (mouseDown) {
startDrag("_root.box", true);
}
onClipEvent (load) {
stopDrag();
}

any idea?

Xansi
10-17-2002, 03:34 PM
ooooooops!!! , I made a mistake on the script, the real script I am using is:

onClipEvent (mouseDown) {
startDrag("_root.box", true);
}
onClipEvent (mouseUp) {
stopDrag();
}

sorry! :D :D :D

tg
10-17-2002, 04:16 PM
onClipEvent(mouseDown) detects the mouse activity anywhere on the flash movie, not specifically your movieclip (i know, not very intuitive).
so you need to add a hitTest to it also.

do a search on hitTest, youll find many results.

Xansi
10-17-2002, 04:31 PM
:D :D thanks tg!
I'll try this hitTest stuff right away.

toke
10-17-2002, 04:33 PM
or you can do this too..

disable your script in the dragMovie named "box" and use this script instead... put this on the first frame action

box.onPress=function(){
this.startDrag();
};


box.onRelease=function(){
this.stopDrag();
};

so when you click anywhere on the stage the drag movie will just stay until you click on it and start to drag.

am i answering the right question? :eek:

tg
10-17-2002, 04:36 PM
yep toke, if xansi is using mx, thats the easiest solution.

Xansi
10-17-2002, 04:44 PM
thanks guys, the solution of toke worked well (yes, I'm using MX), but the MC behaves like a button (the cursor changes to a hand), how can I keep it like an arrow?
is this possible?

toke
10-17-2002, 07:27 PM
ok.. in that case use this script instead..

onClipEvent (mouseDown){

if(this.hitTest(_root._xmouse,_root._ymouse)){
startDrag(this, true);
}

}

onClipEvent (mouseUp){

stopDrag();

}

or replace "this" with "_root.box" anyway.. work the same.

this is the "hitTest" method that tg was referring to. place the above script on your dragMovie object. should do it.

:D

tg
10-17-2002, 07:31 PM
toke, your mx suggestion looks to be a hit.

to avoid the 'finger' use:

//tokes code
box.onPress=function(){
this.startDrag();
};


box.onRelease=function(){
this.stopDrag();
};

box.onRollOver=function(){
this.useHandCursor=false;//add this line... should do it.
};

toke
10-17-2002, 07:44 PM
cool! i'll remember that.

learn a lot of things from you. :D

Xansi
10-17-2002, 07:44 PM
Wow! It worked!

tg & toke, you guys are great

Thanks