4.1 using _droptarget to detect when a drag is released on a target
Regarding _droptarget The Flash 8 manual tells us :
Returns the absolute path in slash-syntax notation of the movie clip instance on which this movie clip was dropped. The _droptarget property always returns a path that starts with a slash (/). To compare the _droptarget property of an instance to a reference, use the eval() function to convert the returned value from slash syntax to a dot-syntax reference. Note: You must perform this conversion if you are using ActionScript 2.0, which does not support slash syntax. |
Let's add a bit more code to our movie to see how we can retrieve the instance name of the target using _droptarget.
onMouseMove = function(){ |
As you might have noticed we created a function called checkTarget, that function is called each time the onRelease or onReleaseOutside events are triggered.
We are passing a reference to the drag to the function using the this keyword which is a necessary step as we need to retrieve the _droptarget property for that particular drag.
Since _dropTarget is an old property coming from Flash 4, we use the eval method to convert the slash syntax to a dot syntax reference.
If you test your movie you will notice that when you release the drag on the target it will display the instance name of the target like _level0.redCirclehas been dropped on _level0.greyCircle. This is indeed very useful but we have a problem. The problem is that the _droptarget property is not very accurate and if you try to release your drag at the edge of your target you will notice that it doesn't always detect the collision perfectly. Therefore we are going to do it using the better hitTest method.
4.2 using hitTest to detect when a drag is released on a target
Regarding hitTest The Flash 8 manual tells us :
Evaluates the bounding boxes of the target and specified instance, and returns true if they overlap or intersect at any point. |
Continue to next page...