Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
You can handle dragging a sprite using two different techniques: with the mouseMove event or with the startDrag/stopDrag methods. Although you'll be using the latter for the examples in this chapter, let's look at how to use the mouseMove event for dragging first. It will give you some experience in handling the mouseMove event and a deeper understanding of how events work.
By manually handling the mouseMove event, you can update the sprite's position to match the mouse cursor's each time the mouse moves. It's worth noting that this is the only way to drag more than one object at a time. You sometimes run into this when making a custom cursor out of a sprite. The cursor needs to follow the mouse position around, but what if you want to drag something, too? One solution is to use mouseMove for the cursor, and leave the usual drag methods (startDrag/stopDrag) free for normal dragging. So it's a nice little technique to have under your belt, even if you don't use it on a regular basis.