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

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 :slight_smile:

Thanks!

Try this fla, I used a couple of ifs to snap to the right position.

=)

hey, cool :slight_smile:

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

:slight_smile:

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:

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?

=)

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?).

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!

=)

Cool, yeah, I did that… thanks :slight_smile:

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???

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

:slight_smile:

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

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.

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?

on that code writed by you:

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:

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.

=)

ah, okay… i will give it a go :slight_smile:

another tip:

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

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).

=)

thanks :slight_smile:

  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?

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.

=)

strange…

can you check my swf & .fla?

maybe I missed something???

code for the mc:

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:

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);
    }
}

=)

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

:slight_smile:

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).

:-\

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!