# Drag and drop function

**URL:** <https://forum.kirupa.com/t/drag-and-drop-function/65533>\
**Category:** Uncategorized\
**Created:** [September 27, 2004, 1:34pm UTC](https://forum.kirupa.com/t/drag-and-drop-function/65533 "2004-09-27T13:34:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gwana](https://avatars.discourse-cdn.com/v4/letter/g/ba9def/32.png) [@gwana](https://forum.kirupa.com/u/gwana)\
**Post date:** [September 27, 2004, 1:34pm UTC](https://forum.kirupa.com/t/drag-and-drop-function/65533/1 "2004-09-27T13:34:00Z")

</div>

I am trying to create a drag and drop action. I got it done, you can see it at

[http://www.gwana.net/clients/merck2/slide16.swf](http://www.gwana.net/clients/merck2/slide16.swf)

However, what needs to happen, is rather than counting each element when correctly placed, I need to set it up so that the user will drag and drop all of the elements, then press a submit button, which will then let the user know if they were all correct. If incorrect sort, then it will give a wrong answer animation then reset itself. Does anybody know how to do this?

Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 27, 2004, 1:46pm UTC](https://forum.kirupa.com/t/drag-and-drop-function/65533/2 "2004-09-27T13:46:34Z")

</div>

Well, I guess that there’s some sort of loop that determines how many items are placed correctly, so all you need to do is create a button that launches the same processing.

```auto
submit.onPress = function () {
  // do whatever you do in your loop
} ;

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 27, 2004, 2:37pm UTC](https://forum.kirupa.com/t/drag-and-drop-function/65533/3 "2004-09-27T14:37:48Z")

</div>

This is the script used in one of the dragged objects:

on (press) {  
startDrag("/description");  
}  
on (release, releaseOutside) {  
stopDrag();  
if (getProperty("/description", \_droptarget) eq “\_level4/description\_mask”) {  
/resultform:result = Number(/resultform:result)+1;  
setProperty("/description", \_name, “descriptionlock”);  
}  
if (Number(/resultform:result) == 8) {  
tellTarget ("/") {  
gotoAndPlay(“reward”);  
}  
}  
}

Notice the “if (Number(/resultform:result) == 8)” statement. This is where it is counting the the correct objects. There are to be 8 of them. I’m not that great when it comes to scripting, and need some clarity. I placed a button on stage and added the script you provided, but nothing happened, the objects weren’t snapping onto target.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 27, 2004, 2:43pm UTC](https://forum.kirupa.com/t/drag-and-drop-function/65533/4 "2004-09-27T14:43:00Z")

</div>

You can download the .fla at [http://www.gwana.net/uploads/](http://www.gwana.net/uploads/) to look at the code and how everything works?
