-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathAnim_Frame_Controller.as
More file actions
94 lines (78 loc) · 2 KB
/
Anim_Frame_Controller.as
File metadata and controls
94 lines (78 loc) · 2 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
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 ;
/**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(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
{
trace("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(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
{
targetFrame = frameIndex ;
}
public function gotoFrameLableIndex(index:uint):void
{
targetFrame = frameLables[index].frame ;
}
}
}