Tuesday, March 30, 2010

dragable objects issue

I have a bunch of objects that are dragable. You click and hold the mouse button to drag them around, then release the mouse button to put them back down. The problem is that when an object is dragged so that another object is between it and the mouse cursor, and the mouse button is released, the object gets stuck to the cursor. Clicking and releasing the mouse button is the only way to drop the object. Is there any way to fix this? Or, better yet, is there a way to make it so an object is immediatelly moved in front of every other object when it's clicked on?

dragable objects issue

That is because it is what you have told flash to do and not what you want flash to do!

So the first part of the answer is that you have forgotten (or perhaps never knew) the onReleaseOutside event. Many programers forget to define this event. It is one of the things that I look at when I want to access someones knowledge and skill in programming flash.

So where you have

myClip.onRelease=someFunction

you could do

myClip.onRelease=myClip.onReleaseOutside=someFunction

or you can define a completely different function for the onReleaseOutside event if you want to do so. This is also really important when you are constraining your drag to a certain area of the stage because the pointer is very likely to ''move off'' the clip and then there won't be a release event just a release outside event.

As for the other part of your question, yes. You can use swapDepths() to change the stacking order of clips. On one level swapdepths is very simple. But on another people seem to get very confused. I recommend that you read this tutorial:

http://www.kirupa.com/developer/actionscript/depths.htm

There are many approaches as to how best to manipulate depths and design your interaction to make this work. So I can't just give you a, ''here...do this'' kind of answer on that front.

dragable objects issue

I just tried adding onReleaseOutside and it works perfectly. Thank you so much. And thanks for the link to the swapDepth tutorial. I've been wanting to learn about the various ways you can handle changing object depths.

Glad that worked out for you.

No comments:

Post a Comment