-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathContDown.as
More file actions
80 lines (73 loc) · 1.95 KB
/
ContDown.as
File metadata and controls
80 lines (73 loc) · 1.95 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
package
{
import flash.display.MovieClip;
import flash.events.TimerEvent;
import flash.utils.Timer;
public class ContDown extends MovieClip
{
private var countDownDate:Number;
private var now:Number;
private var timer:Timer;
private var weekS:Boolean,
daysS:Boolean,
hoursS:Boolean,
minutesS:Boolean,
secondsS:Boolean;
public var contDown:String;
private var onContDownFun:Function;
public function ContDown()
{
super();
}
public function setup(StartDate_p:Date,onContDownFun_p:Function,week_p:Boolean=true,days_p:Boolean=true,hours_p:Boolean=true,minutes_p:Boolean=true,seconds_p:Boolean=true):void
{
weekS = week_p;
daysS = days_p;
hoursS = hours_p;
minutesS = minutes_p;
secondsS = seconds_p;
onContDownFun = onContDownFun_p;
countDownDate = StartDate_p.time
timer = new Timer(1000)
timer.addEventListener(TimerEvent.TIMER,contDownTimer);
timer.start();
}
protected function contDownTimer(event:TimerEvent):void
{
now = new Date().time
var distance:Number = countDownDate - now;
var days:Number = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours:Number = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes:Number = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds:Number = Math.floor((distance % (1000 * 60)) / 1000);
var week:Number = Math.floor(days/7);
contDown = '';
if(weekS)
{
contDown = Add_Zero_Behind.add(2,week) + "w ";
}
if(daysS)
{
contDown += Add_Zero_Behind.add(2,days) + "d ";
}
if(hoursS)
{
contDown += Add_Zero_Behind.add(2,hours) + "h ";
}
if(minutesS)
{
contDown += Add_Zero_Behind.add(2,minutes) + "m ";
}
if(secondsS)
{
contDown += Add_Zero_Behind.add(2,seconds) + "s ";
}
onContDownFun();
}
public function remove():void
{
timer.stop();
timer.removeEventListener(TimerEvent.TIMER,contDownTimer);
}
}
}