Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

65 users online



Drag and drop - Am I stupid?

Drag and drop - Am I stupid?

Currently viewing this thread: 1 (0 members and 1 guests)


Page 1 out of 2
jonnythrillcox

jonnythrillcox

Illustration major at Columbia College Chicago
Status: Offline!

Drag and drop - Am I stupid?

I don't understand why this is not working. I've tried it a few different ways. I'm trying to get simple drag and drop to work. I'm using Flash MX 2004 Pro and exporting in player 7 with AS 2.0.

I have a button that's dragable. I have a box that's the drop target. the code for my button is as follows:

on (press) {
startDrag("circle");
}
on (release) {
stopDrag();
if (eval(circle._droptarget) == _root.square) {
circle._visible = false;
} else {
circle._x = 58;
circle._y = 154;
}
}

That is all taken directly from a tutorial FLA file. It doesn't work for me. It doesn't seem to be reading the drop target. I have the instance names set and everything. I've also tried it with different kind of code, like using hitTest() and adding or subtracting quotes. Any help??

devonair

devonair

Neverside Newbie
Status: Offline!

jonny,

try this on your timeline..

PHP:

<?php
var origX:Number circle_mc._x;
var 
origY:Number circle_mc._y;
circle_mc.onPress = function() {
    
this.startDrag();
};
circle_mc.onRelease circle_mc.onReleaseOutside=function () {
    
stopDrag();
    if (eval(
this._droptarget) == square_mc) {
        
this._visible false;
    } else {
        
this._x origX;
        
this._y origY;
    }
};
?>

that'll do the trick..

d.

___________________

obod | weapons of mass dysfunction

jonnythrillcox

jonnythrillcox

Illustration major at Columbia College Chicago
Status: Offline!

Thanks for the response, however, when i put that in my timeline and tested it, nothing happens at all. my circle button won't drag. does the button HAVE to be nested inside a movie clip, or doesn't that matter?

devonair

devonair

Neverside Newbie
Status: Offline!

there's no reason to use a button at all.. that could have been the original problem.. just a circle movie clip is all you need.

___________________

obod | weapons of mass dysfunction

jonnythrillcox

jonnythrillcox

Illustration major at Columbia College Chicago
Status: Offline!

Got it, thanks a lot.

-Jon

jonnythrillcox

jonnythrillcox

Illustration major at Columbia College Chicago
Status: Offline!

Ok, one more question. It's more about the logical or statement ( || ) but I'm trying to use it with drag and drop. I got the DnD all set up. I'm making a key terms glossary quiz. I have 9 dragable "term" movieclips, and a drop target with the definition text in it that changes each frame. I have it set right now so that if you match them correctly, you get congratulated and it goes to the next frame. If you drag the wrong term down, it tells you it was wrong and the term snaps back into place. I have it set so if you drag it outside of the droptarget nothing happens but making an invisible droptarget named "deadSpace" behind everything.

My problem is, if I drag any term and drop it over any of the other 8 terms, it goes through the process that happens if you dont match them up correctly, and it says you were wrong. I have it set like this currently for that part:

if (eval(this._droptarget) == deadSpace) {
this._x = -193;
this._y = -299.6;
}

i tried doing something like this:

if (eval(this._droptarget) == deadSpace || term01 || term02 || term03 etc...) {

but it didn't work. Am I declaring that incorrectly or is it just not possible?

sorry im so damned confusing.

devonair

devonair

Neverside Newbie
Status: Offline!

If I understand you correctly, the "deadSpace" mc shouldn't be necessary. Just by telling the draggable mc what to do if it's not over the target is enough. Check out the quickie example attached. If you drag the green (or whatever color it is) circle into the blue box, you'll get a big "wrong" response, but if you drag in the blue circle, you'll go to the next frame. If you let either go outside the box or on top of the other, it just snaps back to place.. hopefully, I understood what you were getting at and this'll help..

d.

Attachments:

dndexample.zip 5.59 Kb, 26 views

___________________

obod | weapons of mass dysfunction

jonnythrillcox

jonnythrillcox

Illustration major at Columbia College Chicago
Status: Offline!

Here's an example of what I'm doing. I should have just put this up to begin with.

Anyway, as you can see, the buttons flip out. some can be clicked randomly and they dissapear, etc.

The problem is I had to turn the lone
} else {

into

} else if (eval(this._droptarget) != droptarget1){

because in each frame I have a different instance of the droptarget. Maybe I'm just making it too complicated for my own good?

I want it so that:
1. if you drop the right button on the right target, it congratulates and goes to the next frame
2. if you drop the wrong button on the current target, it scolds you and snaps the button back up
3. if you drop any button anywhere outside of the target area, it snaps back into place, and does nothing else.

I reeeeally appreciate your help! and thanks in advance.

Again, I hope this isn't too complicated...

-Jon

Attachments:

dndexample2.zip 6.03 Kb, 24 views

Last edited by jonnythrillcox, August 4th, 2004 05:14 AM (Edited 1 times)

etcher

etcher

Status: Offline!

The draggables have to be able to see their target or they will act erratically. What I did was separate the instances onto different layers on top of each other so that when the first draggable disappears so does its droptarget.

I am sure the code could still be optimized even further, so the same AS doesn't have to be on every frame but you will get the general idea from the fla.

--edit-- You can edit it down further by taking off the code on frames 2,3 and 4 and just leave the stop actions. (You can also leave the trace actions if you like.)

Attachments:

dndexample2.zip 11.82 Kb, 26 views

Last edited by etcher, August 4th, 2004 03:40 PM (Edited 1 times)

jonnythrillcox

jonnythrillcox

Illustration major at Columbia College Chicago
Status: Offline!

Thanks much for the help.

You fixed my problem with the clicking and making the buttons dissapear in random order, so thanks for that.

However, I'd like to code it somehow so that if you drop a button on another button, or simply outside of any of the target boxes, it will just snap into place and not display a "right" or "wrong" text. I'm just having a hard time figuring out how to do this.

Page 1 out of 2
Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0095 seconds.