AS3 startDrag/stopDrag is similar to AS2 except it uses mouse events to detect the mouse movement, below is a simple implementation:
package {
import flash.display.*;
import flash.events.*;
public class DragExample extends Sprite {
function DragExample() {
addEventListener(MouseEventType.MOUSE_DOWN, onMouseDown);
stage.addEventListener(MouseEventType.MOUSE_UP, onMouseUp);
}
private function onMouseDown(event:Event):Void {
this.startDrag();
}
private function onMouseUp(event:Event):Void {
this.stopDrag();
}
}
}
You will need stage to listen to mouse up event in order to stop dragging as you might release your mouse too quick or not on the sprite.
No user commented in " AS3 startDrag/stopDrag example "
Follow-up comment rss or Leave a TrackbackLeave A Reply