-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathMediaSlider.as
More file actions
128 lines (109 loc) · 2.82 KB
/
MediaSlider.as
File metadata and controls
128 lines (109 loc) · 2.82 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package mp3Player
//mp3Player.MediaSlider
{
import flash.display.Graphics;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
public class MediaSlider extends MovieClip
{
private var backColor:uint;
private var mainColor:uint;
private var onChanged:Function;
private var currentPrecent:Number = 1 ;
private var floatedPrecent:Number = 1 ;
private var myWidth:Number ;
private var myHeight:Number ;
private var lastFloatedPrecent:Number;
private var slideSpeed:Number = 4 ;
/**userSlideEnabled()<br>
* setUp()<br>
* setPrecent(precent:Number)
* */
public function MediaSlider()
{
super();
this.addEventListener(Event.REMOVED_FROM_STAGE,unLoad);
this.buttonMode = true ;
this.mouseChildren = false;
myWidth = this.width ;
myHeight = this.height ;
this.scaleX = this.scaleY = 1 ;
this.removeChildren();
}
override public function set height(value:Number):void
{
myHeight = value ;
}
protected function unLoad(event:Event):void
{
this.removeEventListener(Event.ENTER_FRAME,animIt);
this.removeEventListener(Event.REMOVED_FROM_STAGE,unLoad);
this.removeEventListener(MouseEvent.CLICK,changePrecent);
}
/**precent changed*/
protected function changePrecent(event:MouseEvent):void
{
if(onChanged!=null)
{
//Calculate current precent
var myPrecent:Number = this.mouseX / myWidth;
if(myPrecent<0)
{
myPrecent = 0 ;
}
else if(myPrecent > 1)
{
myPrecent = 1 ;
}
currentPrecent = myPrecent ;
//trace("Touched Precent is : "+currentPrecent);
onChanged(currentPrecent);
}
}
/**set up the slider*/
public function setUp(MainColor:uint,BackColor:uint,onPrecentChanged:Function)
{
mainColor = MainColor ;
backColor = BackColor ;
onChanged = onPrecentChanged ;
this.addEventListener(Event.ENTER_FRAME,animIt);
animIt();
}
/**From now , user can select the slider precent*/
public function userSlideEnabled():void
{
this.addEventListener(MouseEvent.MOUSE_MOVE,changePrecent);
}
/**set the slider to this stage*/
public function setPrecent(precent:Number)
{
if(precent <0)
{
precent = 0 ;
}
else if(precent>1)
{
precent = 1 ;
}
currentPrecent = precent ;
animIt();
}
/**animate the slider*/
private function animIt(e:Event=null)
{
floatedPrecent += (currentPrecent-floatedPrecent)/slideSpeed;
if(floatedPrecent!=lastFloatedPrecent)
{
var gra:Graphics = this.graphics ;
gra.clear();
gra.beginFill(mainColor);
var currentX:Number = floatedPrecent*myWidth ;
gra.drawRect(0,0,currentX,myHeight);
gra.beginFill(backColor);
gra.drawRect(currentX,0,myWidth-currentX,myHeight);
lastFloatedPrecent = floatedPrecent ;
}
}
}
}