# Please help me with this 'Drag&Drop' problem (Flash5)

**URL:** <https://forum.kirupa.com/t/please-help-me-with-this-drag-drop-problem-flash5/9464>\
**Category:** flash\
**Created:** [December 12, 2002, 11:18am UTC](https://forum.kirupa.com/t/please-help-me-with-this-drag-drop-problem-flash5/9464 "2002-12-12T11:18:58Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ericinho](https://avatars.discourse-cdn.com/v4/letter/e/9dc877/32.png) [@ericinho](https://forum.kirupa.com/u/ericinho)\
**Post date:** [December 12, 2002, 11:18am UTC](https://forum.kirupa.com/t/please-help-me-with-this-drag-drop-problem-flash5/9464/1 "2002-12-12T11:18:58Z")

</div>

Hi all,

Okay, I want to make a timeline.  
You slide an arrow from left to right and if you drop the arrow on one of the two dropboxes (those transparant squares), a text appears above the timeline.

Pretty basic stuff and as you can see I managed with that (I attached the example .fla for your convenience ).

However, it needs that final touch, and with this I need your help

Basically I want to add two other functionalities to it, but I don’t know how.

**1.** when you slide the arrow now, you can drop it on any place. But that I don’t want that. What I want is that the arrow snaps to the dropbox nearest to the position of the arrow.

or if not possible, at least snap back to the last dropbox (seen from left to right) that was passed or dropped on.  
So on default I guess it should snap back to the start.

I guess I would need the getproperty function for that, but quite frankly I haven’t got a clue how to use that in this particular case.

1. the **second thing** I would like is this:  
now the text only appears when the arrow is dropped on the dropbox. But I want that also when the arrow is slided over the dropbox, the text appears… and on rollOut the text disappears again.

Ofcourse I could put a rollOver script on that dropbox, but in this case it doesn’t work, since as you can see with defining the space the arrow can slide in, it is very well possible that the cursor is far below the arrow and therefore also dropbox, so that doesn’t work.

So how could I do this?  
If someone could help me out, or perhaps point me to a tutorial which covers this, I would be most grateful 🙂

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:** [December 12, 2002, 11:47am UTC](https://forum.kirupa.com/t/please-help-me-with-this-drag-drop-problem-flash5/9464/2 "2002-12-12T11:47:00Z")

</div>

Try this fla, I used a couple of **if** s to snap to the right position.

=)

---

<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:** [December 12, 2002, 11:58am UTC](https://forum.kirupa.com/t/please-help-me-with-this-drag-drop-problem-flash5/9464/3 "2002-12-12T11:58:43Z")

</div>

hey, cool 🙂

however, when I open it it gives an unexpected file format error… FlashMX perhaps?

🙂

---

<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:** [December 12, 2002, 1:52pm UTC](https://forum.kirupa.com/t/please-help-me-with-this-drag-drop-problem-flash5/9464/4 "2002-12-12T13:52:54Z")

</div>

very sorry:(

I keep forgeting that you´re a flash 5 user(the fla is in mx).

But here is the code for the button inside the mc to be dragged:

```php
on (press) {
	startDrag (this, false, 19, 103, 350, 103);
	_root.text.gotoAndStop(1);
	
}
on (release) {
	stopDrag ();
// snaps back if it´s not on the right position
	if (this._x < 230) {
		this._x = 40;
	}
	if (this._x > 244) {
		this._x = 40;
	}
//	
	if (this._droptarget == "/dropbox1") {
		_root.text.gotoAndStop(2);
	}
	else if (this._droptarget == "/dropbox2") {
		_root.text.gotoAndStop(3);
	}
}

```

You´ll have to change the registration point of the mc and the button to the left. Do you know how to do that?

=)

---

<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:** [December 12, 2002, 2:17pm UTC](https://forum.kirupa.com/t/please-help-me-with-this-drag-drop-problem-flash5/9464/5 "2002-12-12T14:17:54Z")

</div>

the registrationpoint?

you mean that I should make sure that the top left corner is the part with what I align the mc and button???

\> and with these if statements I can also fix that if the arrow is near the dropbox, it also snaps to the dropbox (so exactly positioned over the dropbox?).

---

<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:** [December 12, 2002, 3:11pm UTC](https://forum.kirupa.com/t/please-help-me-with-this-drag-drop-problem-flash5/9464/6 "2002-12-12T15:11:07Z")

</div>

> you mean that I should make sure that the top left corner is the part with what I align the mc and button???

No. Go to the mc´s timeline align the button to the left, then go to the button´s timeline do the same to the fill.

> and with these if statements I can also fix that if the arrow is near the dropbox, it also snaps to the dropbox (so exactly positioned over the dropbox?).

Yep!

=)

---

<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:** [December 12, 2002, 5:03pm UTC](https://forum.kirupa.com/t/please-help-me-with-this-drag-drop-problem-flash5/9464/7 "2002-12-12T17:03:39Z")

</div>

Cool, yeah, I did that… thanks 🙂

but, still some things I would like to implement:

**\>** now the text only appears when the arrow is dropped on the dropbox. But I want that also when the arrow is slided over the dropbox, the text appears… and on rollOut the text disappears again.

\*\*\>\*\*and apart from that, when the arrow snaps to the dropbox, the text isn’t displayed, only when you drop it on it with the cursor.  
How can I change that it shows the text also when the arrow snaps on the dropbox???

---

<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:** [December 13, 2002, 8:02am UTC](https://forum.kirupa.com/t/please-help-me-with-this-drag-drop-problem-flash5/9464/8 "2002-12-13T08:02:22Z")

</div>

sorry, fixed a bug in the previous attachment (i deleted the post).

🙂

---

<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:** [December 13, 2002, 10:22am UTC](https://forum.kirupa.com/t/please-help-me-with-this-drag-drop-problem-flash5/9464/9 "2002-12-13T10:22:34Z")

</div>

Well, to that we got to make an enter frame action. Place this code on the **mc** :

```php
onClipEvent (enterFrame) {
	// shows the message if pointer is on the spot 
    if (this._x > 230 && this._x < 244) {
        _root.text.gotoAndStop(3);
    }
}

```

tell me if it works.

---

<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:** [December 13, 2002, 11:33am UTC](https://forum.kirupa.com/t/please-help-me-with-this-drag-drop-problem-flash5/9464/10 "2002-12-13T11:33:12Z")

</div>

ah okay, and so for the other dropbox/texts I give  
else if statements…

so like:  
this.\_x \> 230 && this.\_x \< 244  
\_root.text.gotoAndStop(3);

else if this.\_x \> 244 && this.\_x \< 270  
\_root.text.gotoAndStop(4);

and so on?

---

<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:** [December 13, 2002, 11:54am UTC](https://forum.kirupa.com/t/please-help-me-with-this-drag-drop-problem-flash5/9464/11 "2002-12-13T11:54:16Z")

</div>

on that code writed by you:

```php
else if this._x > 244 && this._x < 270
_root.text.gotoAndStop(4);

```

these numbers are wrong: **this.\_x \> 244 && this.\_x \< 270**

* * *

on this code:

```php
onClipEvent (enterFrame) {
    // shows the message if pointer is on the spot 
    if (this._x > 230 && this._x < 244) {
        _root.text.gotoAndStop(3);
    }
}

```

the **this.\_x \> 230 && this.\_x \< 244** tell us that if the pointer (that has a width of 14px) is exactly between 230px and 244px in the x axis the condition is met. note that 244px - 230px = 14px(width of the pointer). So, if you will gonna add more message spots you will have to calculate the exactly location were the pointer should be to a message appear, just as I did in the code above.

Tips: Use the info and the align panels.

=)

---

<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:** [December 13, 2002, 11:59am UTC](https://forum.kirupa.com/t/please-help-me-with-this-drag-drop-problem-flash5/9464/12 "2002-12-13T11:59:18Z")

</div>

ah, okay… i will give it a go 🙂

---

<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:** [December 13, 2002, 1:20pm UTC](https://forum.kirupa.com/t/please-help-me-with-this-drag-drop-problem-flash5/9464/13 "2002-12-13T13:20:41Z")

</div>

another tip:

add a trace command to the enter frame code on the mc like this:

```php
trace (this._x);

```

and then test the movie, drag the pointer around the screen and write down the values in the output window, where you want the pointer to be (from beginning to end).

=)

---

<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:** [December 13, 2002, 1:43pm UTC](https://forum.kirupa.com/t/please-help-me-with-this-drag-drop-problem-flash5/9464/14 "2002-12-13T13:43:05Z")

</div>

thanks 🙂

1. ===  
however, this code only partly solved the problem.

as you can see, when the arrow snaps to one of the dropboxes, the text doesn’t appear…

it seems you really need to ‘hold’ the arrow with your cursor to get the onRelease part working.

Is their a way to get around that, to detect if the arrow mc is over the dropbox and then trigger the textmc to play?

1. ===

also I noticed is that if you slide the arrow quickly over the dropboxes, the textmc is not being triggered. Any way to fix that?

---

<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:** [December 13, 2002, 1:55pm UTC](https://forum.kirupa.com/t/please-help-me-with-this-drag-drop-problem-flash5/9464/15 "2002-12-13T13:55:46Z")

</div>

1: it works fine for me:-\

2: no that I know. unless you enlarge the area to be droped, but that will be a bad trade IMO.

=)

---

<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:** [December 13, 2002, 1:58pm UTC](https://forum.kirupa.com/t/please-help-me-with-this-drag-drop-problem-flash5/9464/16 "2002-12-13T13:58:04Z")

</div>

strange…

can you check my swf & .fla?

maybe I missed something???

---

<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:** [December 13, 2002, 2:32pm UTC](https://forum.kirupa.com/t/please-help-me-with-this-drag-drop-problem-flash5/9464/17 "2002-12-13T14:32:44Z")

</div>

code for the mc:

```php
onClipEvent (enterFrame) {
	// shows the message if pointer is on the spot 
    if (this._x > 40&& this._x < 54) {
        _root.text.gotoAndStop(2);
    }else if (this._x > 230&& this._x < 244) {
		_root.text.gotoAndStop(3);
// hides the message if pointer is not on the spot
    }else if (_root.pointer.spot == 0) {
		_root.text.gotoAndStop(1);
	}
}

```

code for the button inside the mc:

```php
on (press) {
    startDrag (this, false, 5, 103, 350, 103);
	_root.pointer.spot = 0;
}
on (release, releaseOutside) {
    stopDrag ();
// snaps to position one
    if (this._x > 40&& this._x < 54) {
        this._x = 40;
		_root.pointer.spot = 1;
// snaps to position two
    }else if (this._x > 230 && this._x < 244) {
        this._x = 230;
		_root.pointer.spot = 2;
// snaps back if it´s not on the right position
    } else {
        this._x = 6;
		_root.pointer.spot = 0;
    }
//
    if (this._droptarget == "/dropbox1") {
        _root.text.gotoAndStop(2);
    }
    else if (this._droptarget == "/dropbox2") {
        _root.text.gotoAndStop(3);
    }
}

```

=)

---

<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:** [December 13, 2002, 2:54pm UTC](https://forum.kirupa.com/t/please-help-me-with-this-drag-drop-problem-flash5/9464/18 "2002-12-13T14:54:44Z")

</div>

mmm, now it only snaps to default (start) and not at all anymore to the dropboxes…

🙂

---

<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:** [December 13, 2002, 3:03pm UTC](https://forum.kirupa.com/t/please-help-me-with-this-drag-drop-problem-flash5/9464/19 "2002-12-13T15:03:00Z")

</div>

How come? I´m pretty sure that this is only flash 5 syntax.

I don´t get that. I works perfectly for me.

The AS panel marks somethig as wrong in the code ?

post your fla with htat code for me plz. I got to look what is wrong, even tho I can´t save it for you(MX).

:-\

---

<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:** [December 13, 2002, 3:18pm UTC](https://forum.kirupa.com/t/please-help-me-with-this-drag-drop-problem-flash5/9464/20 "2002-12-13T15:18:59Z")

</div>

no, no script errors

and I view it with FlashMX in the browser and Flash5 in the Flashplayer… both don’t work??? And mind you, I do publish it with Flash5.

Thanks for your help!

[Next page](https://forum.kirupa.com/t/please-help-me-with-this-drag-drop-problem-flash5/9464.md?page=2)
