PDA

View Full Version : drag and drop



apple
September 8th, 2003, 04:16 AM
i'm now trying to create a drag and drop application. Once i dragged the object to the target area, what should i do to make it movable false after i dropped it.:q:

jingman
September 8th, 2003, 04:55 AM
Honestly (and I'm saying this in the nicest way) you need to look through the tutorial list, and use the search function for the forum.

http://www.kirupaforum.com/forums/showthread.php?s=&threadid=27304&highlight=drag+and+drop
http://www.kirupa.com/developer/actionscript/dragdrop.htm

apple
September 8th, 2003, 05:41 AM
jingman, but what i what is once the object has been dragged to the correct target area, it cannot drag anymore. So, what should i do??

One more thing, how to change the pointer into hand shape when mouse down the object??

comicGeek
September 8th, 2003, 06:04 AM
Disable it!


//if the object being dragged is dropped then...
this.enabled == false;

That should work!

jingman
September 8th, 2003, 11:19 AM
Originally posted by apple
jingman, but what i what is once the object has been dragged to the correct target area, it cannot drag anymore. So, what should i do??

One more thing, how to change the pointer into hand shape when mouse down the object??

With even a basic understanding of AS you should be able to accomplish these two tasks quite easily. You honestly need to read the tutorials and search this forum for solutions.

You'll feel much better having learned these things yourself, without someone just popping out the script for you. I know that this forum is a great resource, but it will be so much more valuable if you build a good AS foundation for yourself.

Jack_Knife
September 9th, 2003, 03:22 AM
Just check a variable when starting the drag, then set it to false (or whatever) when it's in the target area. (I'm not posting the script or nothing, just helping with a way to do it - he is free to build his own AS foundation now)

jingman
September 9th, 2003, 03:39 AM
Originally posted by Jack_Knife
Just check a variable when starting the drag, then set it to false (or whatever) when it's in the target area. (I'm not posting the script or nothing, just helping with a way to do it - he is free to build his own AS foundation now)
:beam:

apple
September 9th, 2003, 11:01 PM
have tried out my own. But, the problem is the object still movable after i drop it to the target area.

below is one of the code under the drag object:


onClipEvent (load) {
originalx = _x;
originaly = _y;
}
on (press) {
if (hitTest(_root._xmouse, _root._ymouse, false)) {
startDrag(this, true);
}
}
on (release, releaseOutside) {
if (hitTest(_root.blue) == false) {
_x = originalx;
_y = originaly;
stopDrag();
} else {
stopDrag();
_root.objB == false;
setProperty("/objB", _x, "216");
setProperty("/objB", _y, "102");
}
}

apple
September 9th, 2003, 11:35 PM
To be more clear of what i doing, i will posted my swf file as the fla is too big.

Thanks.

Jack_Knife
September 10th, 2003, 04:56 AM
Well for starters you can't use onClipEvent's in AS for buttons.

apple
September 10th, 2003, 09:07 PM
Jack_knife, could u be more specific??

Thanks and hope u kindly reply me again.

Jack_Knife
September 18th, 2003, 05:44 AM
You cannot use onClipEvent events (ie. When you use onClipEvent(load){ ) for button instances. Just make it a movieclip instead of a button, i'm pretty sure the other event functions will still work.

apple
September 18th, 2003, 11:33 PM
thanks for your help jack_knife.

apple
September 18th, 2003, 11:38 PM
i have one questions which is:

If one draggable object can accept in multiple target, for exapmle target 1 and target 2. If i drag the object to target 2 first, it should be accepted and vice versa. So, what should i do to check which target has been dropped to??

Thanks.

jingman
September 19th, 2003, 12:36 AM
here.

The code for the draggable object is very well commented.

jingman
September 19th, 2003, 12:53 AM
Here's a revision - some goodies for you!

(labels on buttons change dynamically with what you name them, indicator text tells you what object was dropped where, etc.)

:rambo:

apple
September 19th, 2003, 01:04 AM
jingman thanks for the sample. If i would like the object to be appear again after the object has dropped to one of the targets, what should i do??

thanks.

jingman
September 19th, 2003, 01:32 AM
use duplicateMovie - read the tutorials.

apple
September 19th, 2003, 03:05 AM
thanks jingman for your advice.

apple
September 24th, 2003, 11:43 PM
i'm facing a problem where in my application, there is three objects and three targets. Each of the object can drag to all the targets. If i have drag any one of the objects to the particular target, it should not be accepted anymore, which means one object to one target. So, how or what should i do to make it happen?

Hope some one could help me out!!

Thanks.

jingman
September 25th, 2003, 01:24 AM
Modify the fla that I made for you so that each target mc has a 'hit' variable that turns to 'true' when you drop an object on it. Everytime you are dropping the object, check if that target's 'hit' variable is 'true' or 'false' and only allow it to stick if it's 'false'.

apple
September 25th, 2003, 03:21 AM
jingman, where should i put in the condition??

apple
September 25th, 2003, 03:28 AM
jingman, i have made the changes in the fla that you created for me. Could u please check it for me??

Thanks for your help!!