New MouseMove Behavior
The mouseMove event has changed a little in ActionScript 3. Before, mouseMove events were global meaning that no matter where the mouse was in the Flash movie, if it moved, any listener to Mouse or any MovieClip (which automatically receive mouse events without being made listeners of Mouse) would recognise that it moved and recieve the event.
With ActionScript 3, the Mouse object is no longer used for dispatching mouse events. For mouseMove events, you would listen to InteractiveObject instances such as Sprites, MovieClips, and the Stage. So instead of adding listeners to Mouse, you would use some InteractiveObject. For each InteractiveObject instance, though, the mouseMove event is only called when the mouse moves from one location on that object to another location on that object. For a mouseMove event anywhere in the movie, you would want to add your listener(s) to the Stage instance.
Given this behavior, when using mouseMove to drag objects, you would always want to use Stage as your dispatcher in the case that when you move the mouse, the location it moves is off the object your dragging. If that were to happen, the mouseMove event wouldnt not fire and your drag would stop.
ActionScript Code:
stage.addEventListener(MouseEvent.MOUSE_MOVE, dragMyObject);

0 评论:
发表评论