Repository navigation
Expand file tree
/
Copy pathAnim_Frame_Controller.as
More file actions
123 lines (104 loc) · 2.47 KB
/
Copy pathAnim_Frame_Controller.as
File metadata and controls
123 lines (104 loc) · 2.47 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
package animation
{
import flash.display.FrameLabel;
import flash.display.MovieClip;
import flash.events.Event;
public class Anim_Frame_Controller
{
private var mc:MovieClip ;
private var frameLables:Vector.<FrameLabel> ;
private var targetFrame:uint,
currentFrame:Number;
private var V:Number = 0 ;
public var animSpeed:Number = 5 ;
private var autoPlay:int = 0 ;
/**is it using built in accelerator or not*/
private var acc:Boolean ;
public function Anim_Frame_Controller(yourMovieClip:MovieClip,firstLableIndexToGo:uint = 0,withAccelerator:Boolean=true)
{
mc = yourMovieClip;
acc = withAccelerator ;
var framesL:Array = mc.currentLabels ;
frameLables = new Vector.<FrameLabel>();
for(var i:int = 0 ; framesL!=null && i<framesL.length ; i++)
{
frameLables.push(framesL[i]);
}
mc.stop();
if(frameLables!=null && frameLables.length>0)
{
mc.gotoAndStop(frameLables[firstLableIndexToGo].frame);
}
else
{
mc.gotoAndStop(Math.min(mc.totalFrames,firstLableIndexToGo));
}
mc.addEventListener(Event.ENTER_FRAME,anim);
mc.addEventListener(Event.REMOVED_FROM_STAGE,unLoad);
currentFrame = targetFrame = mc.currentFrame ;
}
public function get totalFrames():uint
{
return mc.totalFrames;
}
protected function unLoad(event:Event):void
{
SaffronLogger.log("Animation for "+mc+" is removed");
mc.removeEventListener(Event.ENTER_FRAME,anim);
mc.removeEventListener(Event.REMOVED_FROM_STAGE,unLoad);
}
protected function anim(event:Event):void
{
if(autoPlay>0)
{
mc.nextFrame();
if(mc.currentFrame==mc.totalFrames)
{
mc.gotoAndStop(1);
}
}
else if(autoPlay<0)
{
mc.prevFrame();
if(mc.currentFrame==1)
{
mc.gotoAndStop(mc.totalFrames);
}
}
else if(acc)
{
V = (targetFrame-mc.currentFrame)/animSpeed ;
currentFrame += V ;
mc.gotoAndStop(Math.round(currentFrame));
}
else
{
if(targetFrame>mc.currentFrame)
{
mc.nextFrame();
}
else if(targetFrame<mc.currentFrame)
{
mc.prevFrame();
}
}
}
public function gotoFrame(frameIndex:uint):void
{
autoPlay = 0 ;
targetFrame = Math.min(mc.totalFrames,frameIndex) ;
}
public function gotoFrameLableIndex(index:uint):void
{
targetFrame = frameLables[index].frame ;
}
public function play():void
{
autoPlay = 1;
}
public function revet():void
{
autoPlay = -1 ;
}
}
}