|
11
|
1 |
package com.eclecticdesignstudio.motion { |
|
|
2 |
|
|
|
3 |
|
|
|
4 |
import com.eclecticdesignstudio.motion.actuators.GenericActuator; |
|
|
5 |
import com.eclecticdesignstudio.motion.actuators.MethodActuator; |
|
|
6 |
import com.eclecticdesignstudio.motion.actuators.MotionInternal; |
|
|
7 |
import com.eclecticdesignstudio.motion.actuators.MotionPathActuator; |
|
|
8 |
import com.eclecticdesignstudio.motion.actuators.SimpleActuator; |
|
|
9 |
import com.eclecticdesignstudio.motion.actuators.TransformActuator; |
|
|
10 |
import com.eclecticdesignstudio.motion.easing.Expo; |
|
|
11 |
import com.eclecticdesignstudio.motion.easing.IEasing; |
|
|
12 |
import flash.display.DisplayObject; |
|
|
13 |
import flash.events.Event; |
|
|
14 |
import flash.utils.Dictionary; |
|
|
15 |
|
|
|
16 |
|
|
|
17 |
use namespace MotionInternal; |
|
|
18 |
|
|
|
19 |
|
|
|
20 |
/** |
|
|
21 |
* @author Joshua Granick |
|
|
22 |
* @version 1.23 |
|
|
23 |
*/ |
|
|
24 |
public class Actuate { |
|
|
25 |
|
|
|
26 |
|
|
|
27 |
public static var defaultActuator:Class = SimpleActuator; |
|
|
28 |
public static var defaultEase:IEasing = Expo.easeOut; |
|
|
29 |
private static var targetLibraries:Dictionary = new Dictionary (true); |
|
|
30 |
|
|
|
31 |
|
|
|
32 |
/** |
|
|
33 |
* Copies properties from one object to another. Conflicting tweens are stopped automatically |
|
|
34 |
* @example <code>Actuate.apply (MyClip, { alpha: 1 } );</code> |
|
|
35 |
* @param target The object to copy to |
|
|
36 |
* @param properties The object to copy from |
|
|
37 |
* @param customActuator A custom actuator to use instead of the default (Optional) |
|
|
38 |
* @return The current actuator instance, which can be used to apply properties like onComplete or onUpdate handlers |
|
|
39 |
*/ |
|
|
40 |
public static function apply (target:Object, properties:Object, customActuator:Class = null):GenericActuator { |
|
|
41 |
|
|
|
42 |
stop (target, properties); |
|
|
43 |
|
|
|
44 |
var actuateClass:Class = customActuator || defaultActuator; |
|
|
45 |
var actuator:GenericActuator = new actuateClass (target, 0, properties); |
|
|
46 |
|
|
|
47 |
actuator.MotionInternal::apply (); |
|
|
48 |
|
|
|
49 |
return actuator; |
|
|
50 |
|
|
|
51 |
} |
|
|
52 |
|
|
|
53 |
|
|
|
54 |
/** |
|
|
55 |
* Creates a new effects tween |
|
|
56 |
* @param target The object to tween |
|
|
57 |
* @param duration The length of the tween in seconds |
|
|
58 |
* @param overwrite Sets whether previous tweens for the same target and properties will be overwritten (Default is true) |
|
|
59 |
* @return An EffectsOptions instance, which is used to select the kind of effect you would like to apply to the target |
|
|
60 |
*/ |
|
|
61 |
public static function effects (target:DisplayObject, duration:Number, overwrite:Boolean = true):EffectsOptions { |
|
|
62 |
|
|
|
63 |
return new EffectsOptions (target, duration, overwrite); |
|
|
64 |
|
|
|
65 |
} |
|
|
66 |
|
|
|
67 |
|
|
|
68 |
private static function getLibrary (target:Object):Dictionary { |
|
|
69 |
|
|
|
70 |
if (!targetLibraries[target]) { |
|
|
71 |
|
|
|
72 |
targetLibraries[target] = new Dictionary (true); |
|
|
73 |
|
|
|
74 |
} |
|
|
75 |
|
|
|
76 |
return targetLibraries[target]; |
|
|
77 |
|
|
|
78 |
} |
|
|
79 |
|
|
|
80 |
|
|
|
81 |
/** |
|
|
82 |
* Creates a new MotionPath tween |
|
|
83 |
* @param target The object to tween |
|
|
84 |
* @param duration The length of the tween in seconds |
|
|
85 |
* @param properties An object containing a motion path for each property you wish to tween |
|
|
86 |
* @param overwrite Sets whether previous tweens for the same target and properties will be overwritten (Default is true) |
|
|
87 |
* @return The current actuator instance, which can be used to apply properties like ease, delay, onComplete or onUpdate |
|
|
88 |
*/ |
|
|
89 |
public static function motionPath (target:Object, duration:Number, properties:Object, overwrite:Boolean = true):GenericActuator { |
|
|
90 |
|
|
|
91 |
return tween (target, duration, properties, overwrite, MotionPathActuator); |
|
|
92 |
|
|
|
93 |
} |
|
|
94 |
|
|
|
95 |
|
|
|
96 |
/** |
|
|
97 |
* Pauses tweens for the specified target objects |
|
|
98 |
* @param ... targets The target objects which will have their tweens paused. Passing no value pauses tweens for all objects |
|
|
99 |
*/ |
|
|
100 |
public static function pause (... targets:Array):void { |
|
|
101 |
|
|
|
102 |
var actuator:GenericActuator; |
|
|
103 |
var library:Dictionary; |
|
|
104 |
|
|
|
105 |
if (targets.length > 0) { |
|
|
106 |
|
|
|
107 |
for each (var target:Object in targets) { |
|
|
108 |
|
|
|
109 |
library = getLibrary (target); |
|
|
110 |
|
|
|
111 |
for each (actuator in library) { |
|
|
112 |
|
|
|
113 |
actuator.MotionInternal::pause (); |
|
|
114 |
|
|
|
115 |
} |
|
|
116 |
|
|
|
117 |
} |
|
|
118 |
|
|
|
119 |
} else { |
|
|
120 |
|
|
|
121 |
for each (library in targetLibraries) { |
|
|
122 |
|
|
|
123 |
for each (actuator in library) { |
|
|
124 |
|
|
|
125 |
actuator.MotionInternal::pause (); |
|
|
126 |
|
|
|
127 |
} |
|
|
128 |
|
|
|
129 |
} |
|
|
130 |
|
|
|
131 |
} |
|
|
132 |
|
|
|
133 |
} |
|
|
134 |
|
|
|
135 |
|
|
|
136 |
/** |
|
|
137 |
* Resets Actuate by stopping and removing tweens for all objects |
|
|
138 |
*/ |
|
|
139 |
public static function reset ():void { |
|
|
140 |
|
|
|
141 |
var actuator:GenericActuator; |
|
|
142 |
var library:Dictionary; |
|
|
143 |
|
|
|
144 |
for each (library in targetLibraries) { |
|
|
145 |
|
|
|
146 |
for each (actuator in library) { |
|
|
147 |
|
|
|
148 |
actuator.MotionInternal::stop (null, false, false); |
|
|
149 |
|
|
|
150 |
} |
|
|
151 |
|
|
|
152 |
} |
|
|
153 |
|
|
|
154 |
targetLibraries = new Dictionary (true); |
|
|
155 |
|
|
|
156 |
} |
|
|
157 |
|
|
|
158 |
|
|
|
159 |
/** |
|
|
160 |
* Resumes paused tweens for the specified target objects |
|
|
161 |
* @param ... targets The target objects which will have their tweens resumed. Passing no value resumes tweens for all objects |
|
|
162 |
*/ |
|
|
163 |
public static function resume (... targets:Array):void { |
|
|
164 |
|
|
|
165 |
var actuator:GenericActuator; |
|
|
166 |
var library:Dictionary; |
|
|
167 |
|
|
|
168 |
if (targets.length > 0) { |
|
|
169 |
|
|
|
170 |
for each (var target:Object in targets) { |
|
|
171 |
|
|
|
172 |
library = getLibrary (target); |
|
|
173 |
|
|
|
174 |
for each (actuator in library) { |
|
|
175 |
|
|
|
176 |
actuator.MotionInternal::resume (); |
|
|
177 |
|
|
|
178 |
} |
|
|
179 |
|
|
|
180 |
} |
|
|
181 |
|
|
|
182 |
} else { |
|
|
183 |
|
|
|
184 |
for each (library in targetLibraries) { |
|
|
185 |
|
|
|
186 |
for each (actuator in library) { |
|
|
187 |
|
|
|
188 |
actuator.MotionInternal::resume (); |
|
|
189 |
|
|
|
190 |
} |
|
|
191 |
|
|
|
192 |
} |
|
|
193 |
|
|
|
194 |
} |
|
|
195 |
|
|
|
196 |
} |
|
|
197 |
|
|
|
198 |
|
|
|
199 |
/** |
|
|
200 |
* Stops all tweens for an individual object |
|
|
201 |
* @param target The target object which will have its tweens stopped |
|
|
202 |
* @param properties A string, array or object which contains the properties you wish to stop, like "alpha", [ "x", "y" ] or { alpha: null }. Passing no value removes all tweens for the object (Optional) |
|
|
203 |
* @param complete If tweens should apply their final target values before stopping. Default is false (Optional) |
|
|
204 |
*/ |
|
|
205 |
public static function stop (target:Object, properties:Object = null, complete:Boolean = false):void { |
|
|
206 |
|
|
|
207 |
if (target) { |
|
|
208 |
|
|
|
209 |
var actuator:GenericActuator; |
|
|
210 |
var library:Dictionary = getLibrary (target); |
|
|
211 |
|
|
|
212 |
var temp:Object; |
|
|
213 |
|
|
|
214 |
if (properties is String) { |
|
|
215 |
|
|
|
216 |
temp = new Object (); |
|
|
217 |
temp[properties] = null; |
|
|
218 |
properties = temp; |
|
|
219 |
|
|
|
220 |
} else if (properties is Array) { |
|
|
221 |
|
|
|
222 |
temp = new Object (); |
|
|
223 |
|
|
|
224 |
for each (var propertyName:String in properties) { |
|
|
225 |
|
|
|
226 |
temp[propertyName] = null; |
|
|
227 |
|
|
|
228 |
} |
|
|
229 |
|
|
|
230 |
properties = temp; |
|
|
231 |
|
|
|
232 |
} |
|
|
233 |
|
|
|
234 |
for each (actuator in library) { |
|
|
235 |
|
|
|
236 |
actuator.MotionInternal::stop (properties, complete, true); |
|
|
237 |
|
|
|
238 |
} |
|
|
239 |
|
|
|
240 |
} |
|
|
241 |
|
|
|
242 |
} |
|
|
243 |
|
|
|
244 |
|
|
|
245 |
/** |
|
|
246 |
* Creates a tween-based timer, which is useful for synchronizing function calls with other animations |
|
|
247 |
* @example <code>Actuate.timer (1).onComplete (trace, "Timer is now complete");</code> |
|
|
248 |
* @param duration The length of the timer in seconds |
|
|
249 |
* @param customActuator A custom actuator to use instead of the default (Optional) |
|
|
250 |
* @return The current actuator instance, which can be used to apply properties like onComplete or to gain a reference to the target timer object |
|
|
251 |
*/ |
|
|
252 |
public static function timer (duration:Number, customActuator:Class = null):GenericActuator { |
|
|
253 |
|
|
|
254 |
return tween (new TweenTimer (0), duration, new TweenTimer (1), false, customActuator); |
|
|
255 |
|
|
|
256 |
} |
|
|
257 |
|
|
|
258 |
|
|
|
259 |
/** |
|
|
260 |
* Creates a new transform tween |
|
|
261 |
* @example <code>Actuate.transform (MyClip, 1).color (0xFF0000);</code> |
|
|
262 |
* @param target The object to tween |
|
|
263 |
* @param duration The length of the tween in seconds |
|
|
264 |
* @param overwrite Sets whether previous tweens for the same target and properties will be overwritten (Default is true) |
|
|
265 |
* @return A TransformOptions instance, which is used to select the kind of transform you would like to apply to the target |
|
|
266 |
*/ |
|
|
267 |
public static function transform (target:Object, duration:Number = 0, overwrite:Boolean = true):TransformOptions { |
|
|
268 |
|
|
|
269 |
return new TransformOptions (target, duration, overwrite); |
|
|
270 |
|
|
|
271 |
} |
|
|
272 |
|
|
|
273 |
|
|
|
274 |
/** |
|
|
275 |
* Creates a new tween |
|
|
276 |
* @example <code>Actuate.tween (MyClip, 1, { alpha: 1 } ).onComplete (trace, "MyClip is now visible");</code> |
|
|
277 |
* @param target The object to tween |
|
|
278 |
* @param duration The length of the tween in seconds |
|
|
279 |
* @param properties The end values to tween the target to |
|
|
280 |
* @param overwrite Sets whether previous tweens for the same target and properties will be overwritten (Default is true) |
|
|
281 |
* @param customActuator A custom actuator to use instead of the default (Optional) |
|
|
282 |
* @return The current actuator instance, which can be used to apply properties like ease, delay, onComplete or onUpdate |
|
|
283 |
*/ |
|
|
284 |
public static function tween (target:Object, duration:Number, properties:Object, overwrite:Boolean = true, customActuator:Class = null):GenericActuator { |
|
|
285 |
|
|
|
286 |
if (target) { |
|
|
287 |
|
|
|
288 |
if (duration > 0) { |
|
|
289 |
|
|
|
290 |
var actuateClass:Class = customActuator || defaultActuator; |
|
|
291 |
var actuator:GenericActuator = new actuateClass (target, duration, properties); |
|
|
292 |
|
|
|
293 |
var library:Dictionary = getLibrary (actuator.target); |
|
|
294 |
|
|
|
295 |
if (overwrite) { |
|
|
296 |
|
|
|
297 |
for each (var childActuator:GenericActuator in library) { |
|
|
298 |
|
|
|
299 |
childActuator.MotionInternal::stop (actuator.properties, false, false); |
|
|
300 |
|
|
|
301 |
} |
|
|
302 |
|
|
|
303 |
} |
|
|
304 |
|
|
|
305 |
library[actuator] = actuator; |
|
|
306 |
actuator.MotionInternal::move (); |
|
|
307 |
|
|
|
308 |
return actuator; |
|
|
309 |
|
|
|
310 |
} else { |
|
|
311 |
|
|
|
312 |
return apply (target, properties, customActuator); |
|
|
313 |
|
|
|
314 |
} |
|
|
315 |
|
|
|
316 |
} |
|
|
317 |
|
|
|
318 |
return null; |
|
|
319 |
|
|
|
320 |
} |
|
|
321 |
|
|
|
322 |
|
|
|
323 |
MotionInternal static function unload (actuator:GenericActuator):void { |
|
|
324 |
|
|
|
325 |
var library:Dictionary = getLibrary (actuator.target); |
|
|
326 |
delete library[actuator]; |
|
|
327 |
|
|
|
328 |
} |
|
|
329 |
|
|
|
330 |
|
|
|
331 |
/** |
|
|
332 |
* Creates a new tween that updates a method rather than setting the properties of an object |
|
|
333 |
* @example <code>Actuate.update (trace, 1, ["Value: ", 0], ["", 1]).onComplete (trace, "Finished tracing values between 0 and 1");</code> |
|
|
334 |
* @param target The method to update |
|
|
335 |
* @param duration The length of the tween in seconds |
|
|
336 |
* @param start The starting parameters of the method call. You may use both numeric and non-numeric values |
|
|
337 |
* @param end The ending parameters of the method call. You may use both numeric and non-numeric values, but the signature should match the start parameters |
|
|
338 |
* @param overwrite Sets whether previous tweens for the same target and properties will be overwritten (Default is true) |
|
|
339 |
* @return The current actuator instance, which can be used to apply properties like ease, delay, onComplete or onUpdate |
|
|
340 |
*/ |
|
|
341 |
public static function update (target:Function, duration:Number, start:Array = null, end:Array = null, overwrite:Boolean = true):GenericActuator { |
|
|
342 |
|
|
|
343 |
var properties:Object = { start: start, end: end }; |
|
|
344 |
|
|
|
345 |
return tween (target, duration, properties, overwrite, MethodActuator); |
|
|
346 |
|
|
|
347 |
} |
|
|
348 |
|
|
|
349 |
|
|
|
350 |
} |
|
|
351 |
|
|
|
352 |
|
|
|
353 |
} |
|
|
354 |
|
|
|
355 |
|
|
|
356 |
import com.eclecticdesignstudio.motion.actuators.FilterActuator; |
|
|
357 |
import com.eclecticdesignstudio.motion.actuators.GenericActuator; |
|
|
358 |
import com.eclecticdesignstudio.motion.actuators.TransformActuator; |
|
|
359 |
import com.eclecticdesignstudio.motion.Actuate; |
|
|
360 |
import flash.display.DisplayObject; |
|
|
361 |
import flash.filters.BitmapFilter; |
|
|
362 |
import flash.filters.ColorMatrixFilter; |
|
|
363 |
import flash.geom.Matrix; |
|
|
364 |
|
|
|
365 |
|
|
|
366 |
class EffectsOptions { |
|
|
367 |
|
|
|
368 |
|
|
|
369 |
protected var duration:Number; |
|
|
370 |
protected var overwrite:Boolean; |
|
|
371 |
protected var target:DisplayObject; |
|
|
372 |
|
|
|
373 |
|
|
|
374 |
public function EffectsOptions (target:DisplayObject, duration:Number, overwrite:Boolean) { |
|
|
375 |
|
|
|
376 |
this.target = target; |
|
|
377 |
this.duration = duration; |
|
|
378 |
this.overwrite = overwrite; |
|
|
379 |
|
|
|
380 |
} |
|
|
381 |
|
|
|
382 |
|
|
|
383 |
/** |
|
|
384 |
* Creates a new BitmapFilter tween |
|
|
385 |
* @param reference A reference to the target's filter, which can be an array index or the class of the filter |
|
|
386 |
* @param properties The end properties to use for the tween |
|
|
387 |
* @return The current actuator instance, which can be used to apply properties like ease, delay, onComplete or onUpdate |
|
|
388 |
*/ |
|
|
389 |
public function filter (reference:*, properties:Object):GenericActuator { |
|
|
390 |
|
|
|
391 |
properties.filter = reference; |
|
|
392 |
|
|
|
393 |
return Actuate.tween (target, duration, properties, overwrite, FilterActuator); |
|
|
394 |
|
|
|
395 |
} |
|
|
396 |
|
|
|
397 |
|
|
|
398 |
} |
|
|
399 |
|
|
|
400 |
|
|
|
401 |
class TransformOptions { |
|
|
402 |
|
|
|
403 |
|
|
|
404 |
protected var duration:Number; |
|
|
405 |
protected var overwrite:Boolean; |
|
|
406 |
protected var target:Object; |
|
|
407 |
|
|
|
408 |
|
|
|
409 |
public function TransformOptions (target:Object, duration:Number, overwrite:Boolean) { |
|
|
410 |
|
|
|
411 |
this.target = target; |
|
|
412 |
this.duration = duration; |
|
|
413 |
this.overwrite = overwrite; |
|
|
414 |
|
|
|
415 |
} |
|
|
416 |
|
|
|
417 |
|
|
|
418 |
/** |
|
|
419 |
* Creates a new ColorTransform tween |
|
|
420 |
* @param color The color value |
|
|
421 |
* @param strength The percentage amount of tint to apply (Default is 1) |
|
|
422 |
* @param alpha The end alpha of the target. If you wish to tween alpha and tint simultaneously, you must do them both as part of the ColorTransform. A value of null will make no change to the alpha of the object (Default is null) |
|
|
423 |
* @return The current actuator instance, which can be used to apply properties like ease, delay, onComplete or onUpdate |
|
|
424 |
*/ |
|
|
425 |
public function color (value:Number = 0x000000, strength:Number = 1, alpha:* = null):GenericActuator { |
|
|
426 |
|
|
|
427 |
var properties:Object = { colorValue: value, colorStrength: strength }; |
|
|
428 |
|
|
|
429 |
if (alpha is Number) { |
|
|
430 |
|
|
|
431 |
properties.colorAlpha = alpha; |
|
|
432 |
|
|
|
433 |
} |
|
|
434 |
|
|
|
435 |
return Actuate.tween (target, duration, properties, overwrite, TransformActuator); |
|
|
436 |
|
|
|
437 |
} |
|
|
438 |
|
|
|
439 |
|
|
|
440 |
/** |
|
|
441 |
* Creates a new SoundTransform tween |
|
|
442 |
* @param volume The end volume for the target, or null if you would like to ignore this property (Default is null) |
|
|
443 |
* @param pan The end pan for the target, or null if you would like to ignore this property (Default is null) |
|
|
444 |
* @return The current actuator instance, which can be used to apply properties like ease, delay, onComplete or onUpdate |
|
|
445 |
*/ |
|
|
446 |
public function sound (volume:* = null, pan:* = null):GenericActuator { |
|
|
447 |
|
|
|
448 |
var properties:Object = new Object (); |
|
|
449 |
|
|
|
450 |
if (volume is Number) { |
|
|
451 |
|
|
|
452 |
properties.soundVolume = volume; |
|
|
453 |
|
|
|
454 |
} |
|
|
455 |
|
|
|
456 |
if (pan is Number) { |
|
|
457 |
|
|
|
458 |
properties.soundPan = pan; |
|
|
459 |
|
|
|
460 |
} |
|
|
461 |
|
|
|
462 |
return Actuate.tween (target, duration, properties, overwrite, TransformActuator); |
|
|
463 |
|
|
|
464 |
} |
|
|
465 |
|
|
|
466 |
|
|
|
467 |
} |
|
|
468 |
|
|
|
469 |
|
|
|
470 |
class TweenTimer { |
|
|
471 |
|
|
|
472 |
|
|
|
473 |
public var progress:Number; |
|
|
474 |
|
|
|
475 |
|
|
|
476 |
public function TweenTimer (progress:Number):void { |
|
|
477 |
|
|
|
478 |
this.progress = progress; |
|
|
479 |
|
|
|
480 |
} |
|
|
481 |
|
|
|
482 |
|
|
|
483 |
} |