Ted Patrick > { Events & Community } > Adobe Systems


hacking startDrag() to provide a solid _droptarget solution

I found a solution to a longstanding problem in Flash. In all players, flash does not recalculate the value of _droptarget unless the mouse is moved. The only exception to this rule is when startDrag() is called initally!

In PowerSDK, startDrag() is called via a setInterval, thus _dropTarget is always dead accurate. This is especially true given that PowerSDK is loaded into a high layer _level10000.

Now the problem has changed, startDrag() and stopDrag() no longer work! But wait, there is a fix for that too!

To provide dragging functionality, I rewrote a mirror drag method that supports dragging many items at once.

mymc.drag(0) // no snap to cursor
yourmc.drag(1) //snap to cursor

Let me repeat that: Dragging N movieclips at once with constraints on each clip! Wow, that was easy!

Here is a great example:

http://www.powersdk.com/sample/v16/drag.html

Why would PowerSDK want to know the correct _droptarget?

In order to send contextual onTarget events, I needed to know the _droptarget. Watching changes in _droptarget value, then becomes a great source of events allowing the detection of onTargetRollOver and the mirror onTargetRollOut. Here are the supported events:

MovieClip.onTargetDouble (timer)
MovieClip.onTargetDragDrop (dropee)
MovieClip.onTargetDragOut (dragee,to)
MovieClip.onTargetDragOver (dragee,from)
MovieClip.onTargetEnterFrame (timer)
MovieClip.onTargetKeyDown (code, ascii)
MovieClip.onTargetKeyUp (code, ascii)
MovieClip.onTargetMouseDown ()
MovieClip.onTargetMouseUp ()
MovieClip.onTargetMouseMove (timer)
MovieClip.onTargetPress ()
MovieClip.onTargetRelease ()
MovieClip.onTargetReleaseOutside ()
MovieClip.onTargetRightMouseUp ()
MovieClip.onTargetRightMouseDown ()
MovieClip.onTargetRightMousePress ()
MovieClip.onTargetRightMouseRelease ()
MovieClip.onTargetRightMouseReleaseOutside ()
MovieClip.onTargetRollOut (to)
MovieClip.onTargetRollOver (from)

http://www.powersdk.com/sample/v16/dragdrop.html

The events pass data too. These arguments make it easy to do great things with very little code. They are especially handy in components as they reduce the volume of event handling code and allow movieclips to detect subtle changes in focus without adding anything to a class.

Much more to come!

Ted ;)

0 Responses to “ hacking startDrag() to provide a solid _droptarget solution ”

Post a Comment



© 2008 Ted On Flash