-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMovieClip_Alpha_Animation.as
85 lines (70 loc) · 1.87 KB
/
MovieClip_Alpha_Animation.as
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
package
{
import flash.display.MovieClip;
import flash.display.StageQuality;
import flash.events.Event;
/**
* ...
* @author ShrekShao
*/
public class MovieClip_Alpha_Animation extends MovieClip
{
public static const appear_event:String = "appear";
public static const disappear_event:String = "disappear";
protected static const alpha_speed:Number = 0.1;
protected static const scale_speed:Number = 0.02;
public function MovieClip_Alpha_Animation()
{
addEventListener(Event.ADDED_TO_STAGE, onAddToStage_my);
}
public function onAddToStage_my(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, onAddToStage_my);
Appear();
//addEventListener(disappear_event, Disappear);
}
public function Appear():void
{
stage.quality = StageQuality.LOW;
alpha = 0;
scaleX = 1.0 / alpha_speed * scale_speed + 1.0;
scaleY = scaleX;
addEventListener(Event.ENTER_FRAME, AppearFrameEvent);
}
public function Disappear(e:Event):void
{
stage.quality = StageQuality.LOW;
if (alpha < 1)
{
alpha = 1;
removeEventListener(Event.ENTER_FRAME, AppearFrameEvent);
}
addEventListener(Event.ENTER_FRAME, DisappearFrameEvent);
}
public function AppearFrameEvent(e:Event):void
{
alpha += alpha_speed;
scaleX -= scale_speed;
scaleY = scaleX;
if (alpha >=1)
{
stage.quality = StageQuality.HIGH;
removeEventListener(Event.ENTER_FRAME, AppearFrameEvent);
addEventListener(disappear_event, Disappear);
}
}
public function DisappearFrameEvent(e:Event):void
{
alpha -= alpha_speed;
scaleX += scale_speed;
scaleY = scaleX;
if (alpha <= 0)
{
stage.quality = StageQuality.HIGH;
removeEventListener(Event.ENTER_FRAME, DisappearFrameEvent);
removeEventListener(disappear_event, Disappear);
MovieClip(parent).removeChild(this);
}
}
}
}