-
Notifications
You must be signed in to change notification settings - Fork 0
/
拖曳物件
37 lines (29 loc) · 1 KB
/
拖曳物件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package folder
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
public class Drag extends MovieClip
{
public function Drag():void
{
addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
}
protected function mouseDown(e:Event):void
{
startDrag();
stage.addEventListener(MouseEvent.MOUSE_UP,mouseUp); //listen for mouse up on the stage, in case the finger/mouse moved off of the button accidentally when they release.
addEventListener(Event.ENTER_FRAME,tick); //while the mouse is down, run the tick function once every frame as per the project frame rate
}
protected function mouseUp(e:Event):void
{
removeEventListener(Event.ENTER_FRAME,tick); //stop running the tick function every frame now that the mouse is up
stage.removeEventListener(MouseEvent.MOUSE_UP,mouseUp); //remove the listener for mouse up
stopDrag();
}
protected function tick(e:Event):void
{
// do something while this obj is dragging.
}
}
}