-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSetButton.as
More file actions
147 lines (137 loc) · 2.89 KB
/
SetButton.as
File metadata and controls
147 lines (137 loc) · 2.89 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package
{
import fl.motion.easing.Elastic;
import fl.transitions.Tween;
import fl.transitions.easing.Regular;
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class SetButton
{
public static const NEXT:String="NEXT",
PREV:String="PREV",
HOME:String="HOME";
private var _current:int;
public function get current():int
{
return _current
}
public function set current(Current_p:int):void
{
_current = Current_p
}
private var _min:int,
_total:int,
_target:MovieClip,
_fun:Function;
private var _targetMovie:Object = {}
public function setup(Min_p:int,Total_p:int,Current_p:int)
{
// constructor code
_min = Min_p
_total = Total_p
current = Current_p
}
public function setButtons_fun(Target_p:MovieClip,Button_name_p:String,Fun_p:Function)
{
_target = Target_p
_target.nameBtn = Button_name_p
_targetMovie[Button_name_p] = _target
_fun = Fun_p
_target.addEventListener(MouseEvent.CLICK,click_fun)
chekCurrent(_target,true)
chekButton(_target)
}
protected function click_fun(event:MouseEvent):void
{
for(var targetIndex in _targetMovie)
{
if(event.currentTarget.nameBtn==_targetMovie[targetIndex].nameBtn)
{
chekCurrent(_targetMovie[targetIndex],false)
}
else
{
chekCurrent(_targetMovie[targetIndex],true)
}
}
for(var targetIndexBtn in _targetMovie)
{
chekButton(_targetMovie[targetIndexBtn])
}
}
private function chekCurrent(TargetIndex_p:MovieClip,FirstChek:Boolean):void
{
switch(TargetIndex_p.nameBtn)
{
case NEXT:
if(!FirstChek)
{
current++
_fun.apply()
}
break
case PREV:
if(!FirstChek)
{
current--
_fun.apply()
}
break
case HOME:
if(!FirstChek)
{
current = _min
_fun.apply()
}
break
}
}
private function chekButton(TargetIndex_p:MovieClip):void
{
switch(TargetIndex_p.nameBtn)
{
case NEXT:
if(current>=_total)
{
buttonStatus(TargetIndex_p,false)
}
else
{
buttonStatus(TargetIndex_p,true)
}
break
case PREV:
if(current<=_min)
{
buttonStatus(TargetIndex_p,false)
}
else
{
buttonStatus(TargetIndex_p,true)
}
break
case HOME:
buttonStatus(TargetIndex_p,false)
break
}
}
private function buttonStatus(target_p:Object,status_p:Boolean):void
{
if(status_p)
{
//var fadeIn:Tween = new Tween(target_p,'alpha',Regular.easeInOut,target_p.alpha,1,30)
//fadeIn.start()
target_p.alpha = 1
}
else
{
// var fadeOut:Tween = new Tween(target_p,'alpha',Regular.easeInOut,1,0.3,30)
// fadeOut.start()
target_p.alpha = 0.3
}
target_p.mouseChildren = status_p
target_p.mouseEnabled = status_p
}
}
}