My favorites | Sign in
Project Logo
                
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
package com.vfd.animation{
/**
* Animation class. Based off of mc_tween2.as project.
* @author Jeremy Wischusen <cortex@visualflowdesigns.com>
*/
import flash.display.Sprite;
import fl.transitions.Tween;
import fl.motion.Color;
import flash.geom.ColorTransform;
import fl.transitions.TweenEvent;
import flash.events.Event;
public class AnimatedClip extends Sprite {
private var originalX:Number;
private var originalY:Number;
/*tweens*/
private var _xTween:Tween;
private var _yTween:Tween;
private var _alphaTween:Tween;
private var _rotationTween:Tween;
private var _widthTween:Tween;
private var _heightTween:Tween;
private var colorTween:Tween;
private var tweenArray:Array;
/*end tweens*/
private var colorTrans:ColorTransform;
private var tweenToColor:Number;
private var lastColor:Number;
private var timerClip:Sprite;
private var orbitAngle:Number = 0;
private var _orbitVelocity:Number = .5;
private var _orbitY:Number = stage.stageHeight/2;
private var _orbitX:Number = stage.stageWidth/2;
private var _orbitDistance:Number;


public function AnimatedClip() {
this.originalX = this.x;
this.originalY = this.y;
this._xTween = new Tween(this, "x", null, this.x, this.x, 1, true);
this._yTween = new Tween(this, "y", null, this.y, this.y, 1, true);
this._alphaTween = new Tween(this, "alpha", null, this.alpha, this.alpha, 1, true);
this._rotationTween = new Tween(this, "rotation", null, this.rotation, this.rotation, 1, true);
this._widthTween = new Tween(this, "width", null, this.width, this.width, 1, true);
this._heightTween = new Tween(this, "height", null, this.height, this.height, 1, true);
this.timerClip = new Sprite();
this.colorTween = new Tween(this.timerClip,'alpha',null,0,1,1,true);
this.colorTween.stop();
this.tweenArray = new Array(this._xTween, this._yTween, this._alphaTween, this._rotationTween, this._widthTween, this._heightTween,this.colorTween);
this.colorTrans = this.transform.colorTransform;
this._orbitDistance = this.width*2;
this.colorTween.addEventListener(TweenEvent.MOTION_CHANGE, updateColor);

}
public function resetPosition():void {
this.x = this.originalX;
this.y = this.originalY;
}
public function moveToPoint(x:Number, y:Number,duration:Number = 0, loop:Boolean = false):void {
this._xTween.finish = x;
this._xTween.duration = duration;
this._xTween.looping = loop;
this._yTween.finish = y;
this._yTween.duration = duration;
this._yTween.looping = loop;
this._xTween.start();
this._yTween.start();
}
public function fadeTo(val:Number =0, duration:Number = 0, loop:Boolean = false):void {
this._alphaTween.finish = val;
this._alphaTween.duration = duration;
this._alphaTween.looping=loop;
this._alphaTween.start();
}
public function sizeTo(w:Number, h:Number, duration:Number=0, loop:Boolean = false):void {
this._widthTween.finish=w;
this._widthTween.looping = loop;
this._widthTween.duration = duration;
this._heightTween.finish = h;
this._heightTween.looping = loop;
this._heightTween.duration = duration;
this._widthTween.start();
this._heightTween.start();

}
public function widthTo(width:Number, duration:Number, loop:Boolean = false):void {
this._widthTween.finish =width;
this._widthTween.looping = loop;
this._widthTween.duration = duration;
this._widthTween.start();
}
public function heightTo(height:Number, duration:Number, loop:Boolean = false):void {
this._heightTween.finish =height;
this._heightTween.looping = loop;
this._heightTween.duration = duration;
this._heightTween.start();
}
public function spinTo(rot:Number= 0, duration:Number = 0, loop:Boolean = false):void {
this._rotationTween.finish=rot;
this._rotationTween.duration = duration;
this._rotationTween.looping = loop;
this._rotationTween.start();
}
public function xTo(x:Number, duration:Number = 0, loop:Boolean = false):void {
this._xTween.finish = x;
this._xTween.duration = duration;
this._xTween.looping = loop;
this._xTween.start();
}
public function yTo(y:Number, duration:Number = 0, loop:Boolean = false):void {
this._yTween.finish = y;
this._yTween.duration = duration;
this._yTween.looping = loop;
this._yTween.start();
}
public function set easing(ease:Function):void {
for (var tw in this.tweenArray) {
tweenArray[tw].func = ease;
}
}
public function colorTo(toColor:Number, duration:Number):void {
this.lastColor = this.transform.colorTransform.color;
this.tweenToColor = toColor;
this.colorTween.duration = duration;
this.colorTween.start();
}
private function updateColor(event:TweenEvent):void {
this.colorTrans.color = Color.interpolateColor(this.lastColor, this.tweenToColor,event.position);
updateColorTransform();
}
public function set currentColor(clr:Number) {
this.lastColor = clr;
this.colorTrans.color= clr;
updateColorTransform();

}
public function startOrbit():void {
this.addEventListener(Event.ENTER_FRAME,orbit);
}
public function stopOrbit():void {
this.removeEventListener(Event.ENTER_FRAME,orbit);
this.orbitAngle = 0;
}
private function orbit(event:Event) {
this.y = this._orbitY + Math.sin(this.orbitAngle)*this._orbitDistance;
this.x = this._orbitX + Math.cos(this.orbitAngle)*this._orbitDistance;
this.orbitAngle += this._orbitVelocity;
}
public function set yEasing(ease:Function) {
this._yTween.func = ease;
}
public function set xEasing(ease:Function) {
this._xTween.func = ease;
}
public function set heightEasing(ease:Function) {
this._heightTween.func = ease;
}
public function set widthEasing(ease:Function) {
this._widthTween.func = ease;
}
public function set alphaEasing(ease:Function) {
this._alphaTween.func = ease;
}
public function set rotationEasing(ease:Function) {
this._rotationTween.func = ease;
}
public function set orbitVelocity(velocity:Number) {
this._orbitVelocity = velocity;
}
public function set orbitY(y:Number) {
this._orbitY = y;
}
public function set orbitX(x:Number) {
this._orbitX = x;
}
public function set orbitDistance(distance:Number) {
this._orbitDistance = distance;
}
public function get currentColor():Number {
return this.lastColor;
}
private function updateColorTransform() {
this.transform.colorTransform = this.colorTrans;
}
public function get xTween() {
return _xTween;
}
public function get yTween() {
return _yTween;
}
public function get alphaTween() {
return _alphaTween;
}
public function get rotationTween() {
return _rotationTween;
}
public function get widthTween() {
return _widthTween;
}
public function get heightTween() {
return _heightTween;
}
}
}
Show details Hide details

Change log

r15 by jeremy.wischusen on Aug 14, 2008   Diff
Added getter methods for tween objects so
that they can be referenced for adding
event listeners.
Go to: 
Project members, sign in to write a code review

Older revisions

r12 by jeremy.wischusen on May 14, 2008   Diff
Started As 2 version of AnimatedClip.
Fixed looping in AS 3 version of
AnimatedClip for moveToPoint method.
r11 by jeremy.wischusen on May 14, 2008   Diff
Added package statement back in.
r10 by jeremy.wischusen on May 14, 2008   Diff
Fixed invalid easing assignment
function. Added stop to color tween so
that the color does not get set on
construction.
All revisions of this file

File info

Size: 8295 bytes, 203 lines
Hosted by Google Code