View Full Version : drag and drop
quinu
May 10th, 2002, 11:23 AM
I am boggled. This looks right to me but it won't drag and drop. I would like to drage the mc "medium" over the mc "box". If it is over it on release then lock to the center. Otherwise, go back to its original position. Any suggestions are appreciated.
on (press) {
        startDrag ("_root.medium", true);
}
on (release) {
        stopDrag ();
        if (_root.medium._droptarget = _root.box) {
                _root.medium._y = "129.3");
                _root.medium._x = "350.3");
        } else {
_root.medium._x = "170.4.";
_root.medium._y = "75.9";
        }
}
kitiara30
May 13th, 2002, 08:36 AM
I've had a few problems with getting drag and drop functionality to do exactly what I want, as it seems no two tutorials can quite agree on the best way to do it. I realise there's no _root 's in there whatsoever. But whenever I put them in, the thing wouldn't drag. However, this way seems to work OK for me:
on (press)
{
startDrag ("");
}
on (release)
{
stopDrag ();
if (medium._droptarget == "/box")
{
medium._y = "129.3");
medium._x = "350.3");
}
else
{
medium._x = "170.4.";
medium._y = "75.9";
}
}
Of course I could have got it totally wrong, but it's worth a try.
ilyaslamasse
May 13th, 2002, 07:52 PM
Hue...
on (press) {
startDrag ("_root.medium", true);
}
on (release) {
stopDrag ();
if (_root.medium._droptarget = _root.box) {
_root.medium._y = 129.3;
_root.medium._x = 350.3;
} else {
_root.medium._x = 170.4;
_root.medium._y = 75.9;
}
}maybe ? I just removed the "" and the ).
It's kinda strange though.
pom 0]
Iammontoya
May 13th, 2002, 08:58 PM
well.. please forgive me if Im over-simplifying but, it is worth asking.
a few things:
1.) your code is on a button that is inside a movie clip. Right?
2.) _droptarget returns values in the form /objectname
you have to use eval in order to get dot syntax.
3.) Im assuming you named your instances "box" and "medium"
so.. you can say:
if (_root.medium._droptarget == "/box") //notice the == in your code, you used a single =. Also, notice the quotes when using /box format. And finally, notice use of eval in order to change the expression from /box to _root.box.
or you can say:
if (eval(_root.medium._droptarget)) == _root.box) //notice again double == and lack of quotes when using dot syntax
but I dont think that
if (_root.medium._droptarget = _root.box)
would work. However, I am certainly nowhere near the flash deities on this site (Supra, Upu, Ilia, eyez, etc..). Maybe one day.
After looking at the code you submitted, there were several problems. I have attached working code. Hope this helps.
This works:
on (press) {
startDrag (_root.medium, true);
}
on (release) {
stopDrag ();
_ _ _ _ _ _ _ _ trace(_root.medium._droptarget);
if (_root.medium._droptarget == "/box") {
_ _ _ _ _ _ _ _ _ _ _ _
_root.medium._y = 129.3;
_root.medium._x = 350.3;
}
_ _ _ _ _ _ _ _ else {
_root.medium._x = 10;
_root.medium._y = 10;
}
}
Please notice the following:
In your code you used the = sign. You really need to use == if you're trying to get your if statement to compare.
Also you used "" and ( incorrectly... for example, here are some excerpts of your code..
_root.medium._y = "129.3");
_root.medium._x = "350.3");
the "" and the ) need to go in order for your code to work.
"My name is Inigo Montoya. You killed my father. Prepare to die!"
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.