1 | import mx.utils.Delegate;
|
---|
2 |
|
---|
3 | class Progress extends MovieClip
|
---|
4 | {
|
---|
5 | public var bar_mc:MovieClip;
|
---|
6 | public var track_mc:MovieClip;
|
---|
7 | public var border_mc:MovieClip;
|
---|
8 |
|
---|
9 | private var _movingHead:Boolean;
|
---|
10 | private var _maxPos:Number;
|
---|
11 |
|
---|
12 | public var addListener:Function;
|
---|
13 | public var removeListener:Function;
|
---|
14 | private var broadcastMessage:Function;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * Constructor
|
---|
18 | */
|
---|
19 | function Progress()
|
---|
20 | {
|
---|
21 | AsBroadcaster.initialize(this);
|
---|
22 |
|
---|
23 | this.bar_mc._width = 0;
|
---|
24 | _movingHead = false;
|
---|
25 |
|
---|
26 | this.track_mc.onPress = Delegate.create(this, function() {
|
---|
27 | this._movingHead = true;
|
---|
28 | this._moveProgressBar();
|
---|
29 | });
|
---|
30 | this.track_mc.onMouseMove = Delegate.create(this, function() {
|
---|
31 | if(this._movingHead) this._moveProgressBar();
|
---|
32 | });
|
---|
33 | this.track_mc.onRelease = this.track_mc.onReleaseOutside = Delegate.create(this, function() {
|
---|
34 | this.broadcastMessage("onMoveHead", this.bar_mc._width / this.track_mc._width);
|
---|
35 | this._movingHead = false;
|
---|
36 | });
|
---|
37 | }
|
---|
38 |
|
---|
39 | public function updateProgress(played:Number):Void
|
---|
40 | {
|
---|
41 | if(!_movingHead) bar_mc._width = Math.round(played * track_mc._width);
|
---|
42 | }
|
---|
43 |
|
---|
44 | public function setMaxValue(maxValue:Number):Void
|
---|
45 | {
|
---|
46 | _maxPos = maxValue * this.track_mc._width;
|
---|
47 | }
|
---|
48 |
|
---|
49 | public function resize(newWidth:Number):Void
|
---|
50 | {
|
---|
51 | this.track_mc._width = newWidth - 2;
|
---|
52 | this.border_mc._width = newWidth;
|
---|
53 | }
|
---|
54 |
|
---|
55 | private function _moveProgressBar():Void
|
---|
56 | {
|
---|
57 | var newPos:Number = this._xmouse - 1;
|
---|
58 | if(newPos < 0) newPos = 0;
|
---|
59 | else if(newPos > _maxPos) newPos = _maxPos;
|
---|
60 | this.bar_mc._width = newPos;
|
---|
61 | }
|
---|
62 | } |
---|