This is definitely old knowledge, but for those of us who have not yet stumbled upon everything that ActionScript and Flash can throw at us…
After pulling a few hairs out over a really simple drag and drop using the draggable object’s _dropTarget property, I just discovered this: the _dropTarget value depends not only on what movie clip might be under what you just dragged, it also takes the mouse position into account. Go on, say it: duh! The problem?
Say you’re working with a draggable slider, like a progress bar slider. If the the slider is taller than the progress bar below, you might grab it at the part that isn’t over the bar. Then when you release it, the _dropTarget property of the slider is an empty string, even if you’ve released it over the progress bar. That’s because the draggable object’s _dropTarget property will be the target you dropped in on only if the mouse is over that target too.
Flash 8, ActionScript 2… maybe ActionScript 3 behaves differently? (Like _dropTarget gets deprecated maybe? 😉 See below for update… )
It took a bunch of zooming in to discover why I was getting strange results. Sigh. Here’s a couple screenshots of a test file. ( Can’t embed flash files on a wordpress-hosted blog.) Anyway, the first image below shows the value you get if your draggable slider is released with the mouse over the _dropTarget you’re looking for: the string with the path to the target (named targetBar):
The next screenshot shows that after you release your slider over the target, but your mouse isn’t over the target too, the _dropTarget is an empty string!
Just checked out what happens in ActionScript 3 with Sprite’s dropTarget property (using the example provided in the live docs for the Sprite class’s property dropTarget).
There’s still a problem when you drop the draggable object over the target, but the mouse isn’t over the target too. Instead of an empty string, though, dropTarget is apparently null. Using the example on live docs, we get an error where there’s this code:
“TypeError: Error #1009: Cannot access a property or method of a null object reference.
Long live hitTest().