/
TimelineLite.as
executable file
·1898 lines (1799 loc) · 119 KB
/
TimelineLite.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
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* VERSION: 12.0.3
* DATE: 2013-02-28
* AS3 (AS2 version is also available)
* UPDATES AND DOCS AT: http://www.greensock.com/timelinelite/
**/
package com.greensock {
import com.greensock.TweenLite;
import com.greensock.core.Animation;
import com.greensock.core.SimpleTimeline;
/**
* TimelineLite is a powerful sequencing tool that acts as a container for tweens and
* other timelines, making it simple to control them as a whole and precisely manage their
* timing in relation to each other. Without TimelineLite (or its big brother TimelineMax), building
* complex sequences would be far more cumbersome because you'd need to use the <code>delay</code> special property
* for everything which would make future edits far more tedious. Here is a basic example of a
* sequence <strong>without</strong> using TimelineLite (the tedious way):
* <listing version="3.0">
TweenLite.to(mc, 1, {x:100});
TweenLite.to(mc, 1, {y:50, delay:1});
TweenLite.to(mc, 1, {alpha:0, delay:2});
</listing>
* The above code animates <code>mc.x</code> to 100, then <code>mc.y</code> to 50, and finally
* <code>mc.alpha</code> to 0 (notice the <code>delay</code> in all but the first tween). But
* imagine if you wanted to increase the duration of the first tween to 1.5 - you'd need to
* adjust every delay thereafter. And what if you want to <code>pause()</code> the whole
* sequence or <code>restart()</code> it or <code>reverse()</code> it on-the-fly or jump to
* a specific point in the whole animation? This becomes quite messy (or flat-out impossible),
* but TimelineLite makes it incredibly simple:
*
* <listing version="3.0">
var tl = new TimelineLite();
tl.add( TweenLite.to(mc, 1, {x:100}) );
tl.add( TweenLite.to(mc, 1, {y:50}) );
tl.add( TweenLite.to(mc, 1, {alpha:0}) );
//then later, control the whole thing...
tl.pause();
tl.resume();
tl.seek(1.5);
tl.reverse();
...
</listing>
* Or use the convenient <code>to()</code> method and chaining to make it even more concise:
* <listing version="3.0">
var tl = new TimelineLite();
tl.to(mc, 1, {x:100}).to(mc, 1, {y:50}).to(mc, 1, {alpha:0});
</listing>
*
* <p>Now you can adjust any of the tweens without worrying about trickle-down
* changes to delays. Increase the duration of that first tween and everything automatically
* adjusts!</p>
*
* <p>Here are some other benefits and features of TimelineLite:</p>
*
* <ul>
* <li> Things can overlap on the timeline as much as you want. You have complete control
* over where tweens/timelines are placed. Most other animation tools can only do basic
* one-after-the-other sequencing but can't allow things to overlap. Imagine appending
* a tween that moves an object and you want it to start fading out 0.5 seconds before the
* end of that tween? With TimelineLite it's easy.</li>
*
* <li> Add labels, play(), stop(), seek(), restart(), and even reverse() smoothly anytime.</li>
*
* <li> Nest timelines within timelines as deeply as you want. This means you can modularize
* your code and make it far more efficient. Imagine building your app with common animateIn()
* and animateOut() methods that return a tween or timeline instance, then you can string
* things together like
* <code>myTimeline.add( myObject.animateIn() ).add( myObject.animateOut(), "+=4").add( myObject2.animateIn(), "-=0.5")...</code></li>
*
* <li> Speed up or slow down the entire timeline with its <code>timeScale()</code> method.
* You can even tween it to gradually speed up or slow down the animation smoothly.</li>
*
* <li> Get or set the progress of the timeline using its <code>progress()</code> method.
* For example, to skip to the halfway point, set <code>myTimeline.progress(0.5);</code></li>
*
* <li> Tween the <code>time</code> or <code>progress</code> to fastforward/rewind
* the timeline. You could even attach a slider to one of these properties to give the
* user the ability to drag forward/backward through the timeline.</li>
*
* <li> Add <code>onComplete, onStart, onUpdate,</code> and/or <code>onReverseComplete</code>
* callbacks using the constructor's <code>vars</code> object like
* <code>var tl = new TimelineLite({onComplete:myFunction});</code></li>
*
* <li> Kill the tweens of a particular object inside the timeline with <code>killTweensOf()</code>
* or get the tweens of an object with <code>getTweensOf()</code> or get all the tweens/timelines
* in the timeline with <code>getChildren()</code></li>
*
* <li> By passing <code>useFrames:true</code> in the <code>vars</code> parameter, you can
* base the timing on frames instead of seconds. Please note, however, that
* the timeline's timing mode dictates its childrens' timing mode as well. </li>
*
* <li> You can export all the tween/timelines from the root (master) timeline anytime into
* a TimelineLite instance using <code>TimelineLite.exportRoot()</code> so that
* you can <code>pause()</code> them all or <code>reverse()</code> or alter their
* <code>timeScale</code>, etc. without affecting tweens/timelines that you create in
* the future. Imagine a game that has all its animation driven by the GreenSock
* Animation Platform and it needs to pause or slow down while a status screen pops up.
* Very easy.</li>
*
* <li> If you need even more features like <code>repeat, repeatDelay, yoyo, currentLabel(),
* getLabelAfter(), getLabelBefore(), addCallback(), removeCallback(), getActive()</code>,
* AS3 event listeners and more, check out TimelineMax which extends TimelineLite.</li>
* </ul>
*
*
* <p><strong>SPECIAL PROPERTIES:</strong></p>
* <p>You can optionally use the constructor's <code>vars</code> parameter to define any of
* the special properties below (syntax example: <code>new TimelineLite({onComplete:myFunction, delay:2});</code></p>
*
* <ul>
* <li><strong> delay </strong>:<em> Number</em> -
* Amount of delay in seconds (or frames for frames-based tweens) before the timeline should begin.</li>
*
* <li><strong> paused </strong>:<em> Boolean</em> -
* If <code>true</code>, the timeline will pause itself immediately upon creation (by default,
* timelines automatically begin playing immediately). If you plan to create a TimelineLite and
* then populate it later (after one or more frames elapse), it is typically best to set
* <code>paused:true</code> and then <code>play()</code> after you populate it.</li>
*
* <li><strong> onComplete </strong>:<em> Function</em> -
* A function that should be called when the timeline has completed</li>
*
* <li><strong> onCompleteParams </strong>:<em> Array</em> -
* An Array of parameters to pass the <code>onComplete</code> function. For example,
* <code>new TimelineLite({onComplete:myFunction, onCompleteParams:["param1", "param2"]});</code>
* To self-reference the timeline instance itself in one of the parameters, use <code>"{self}"</code>,
* like: <code>onCompleteParams:["{self}", "param2"]</code></li>
*
* <li><strong> useFrames </strong>:<em> Boolean</em> -
* If <code>useFrames</code> is <code>true</code>, the timelines's timing will be
* based on frames instead of seconds because it is intially added to the root
* frames-based timeline. This causes both its <code>duration</code>
* and <code>delay</code> to be based on frames. An animations's timing mode is
* always determined by its parent <code>timeline</code>.</li>
*
* <li><strong> tweens </strong>:<em> Array</em> -
* To immediately insert several tweens into the timeline, use the <code>tweens</code>
* special property to pass in an Array of TweenLite/TweenMax/TimelineLite/TimelineMax
* instances. You can use this in conjunction with the <code>align</code> and
* <code>stagger</code> special properties to set up complex sequences with minimal code.
* These values simply get passed to the <code>add()</code> method.</li>
*
* <li><strong> align </strong>:<em> String</em> -
* Only used in conjunction with the <code>tweens</code> special property when multiple
* tweens are to be inserted immediately. The value simply gets passed to the
* <code>add()</code> method. The default is <code>"normal"</code>.
* Options are:
* <ul>
* <li><strong><code>"sequence"</code></strong>: aligns the tweens one-after-the-other in a sequence</li>
* <li><strong><code>"start"</code></strong>: aligns the start times of all of the tweens (ignores delays)</li>
* <li><strong><code>"normal"</code></strong>: aligns the start times of all the tweens (honors delays)</li>
* </ul>
* The <code>align</code> special property does <strong>not</strong> force all child
* tweens/timelines to maintain relative positioning, so for example, if you use
* <code>"sequence"</code> and then later change the duration of one of the nested tweens,
* it does <strong>not</strong> force all subsequent timelines to change their position.
* The <code>align</code> special property only affects the alignment of the tweens that are
* initially placed into the timeline through the <code>tweens</code> special property of
* the <code>vars</code> object.</li>
*
* <li><strong> stagger </strong>:<em> Number</em> -
* Only used in conjunction with the <code>tweens</code> special property when multiple
* tweens are to be added immediately. It staggers the tweens by a set amount of time
* in seconds (or in frames if <code>useFrames</code> is true). For example, if the
* stagger value is 0.5 and the "align" property is set to <code>"start"</code>, the
* second tween will start 0.5 seconds after the first one starts, then 0.5 seconds
* later the third one will start, etc. If the align property is <code>"sequence"</code>,
* there would be 0.5 seconds added between each tween. This value simply gets
* passed to the <code>add()</code> method. Default is 0.</li>
*
* <li><strong> onStart </strong>:<em> Function</em> -
* A function that should be called when the timeline begins (when its <code>time</code>
* changes from 0 to some other value which can happen more than once if the
* timeline is restarted multiple times).</li>
*
* <li><strong> onStartParams </strong>:<em> Array</em> -
* An Array of parameters to pass the <code>onStart</code> function. For example,
* <code>new TimelineLite({onStart:myFunction, onStartParams:["param1", "param2"]});</code>
* To self-reference the timeline instance itself in one of the parameters, use <code>"{self}"</code>,
* like: <code>onStartParams:["{self}", "param2"]</code></li>
*
* <li><strong> onUpdate </strong>:<em> Function</em> -
* A function that should be called every time the timeline updates
* (on every frame while the timeline is active)</li>
*
* <li><strong> onUpdateParams </strong>:<em> Array</em> -
* An Array of parameters to pass the <code>onUpdate</code> function. For example,
* <code>new TimelineLite({onUpdate:myFunction, onUpdateParams:["param1", "param2"]});</code>
* To self-reference the timeline instance itself in one of the parameters, use <code>"{self}"</code>,
* like: <code>onUpdateParams:["{self}", "param2"]</code></li>
*
* <li><strong> onReverseComplete </strong>:<em> Function</em> -
* A function that should be called when the timeline has reached its beginning again from the
* reverse direction. For example, if <code>reverse()</code> is called, the timeline will move
* back towards its beginning and when its <code>time</code> reaches 0, <code>onReverseComplete</code>
* will be called. This can also happen if the timeline is placed in a TimelineLite or TimelineMax
* instance that gets reversed and plays the timeline backwards to (or past) the beginning.</li>
*
* <li><strong> onReverseCompleteParams </strong>:<em> Array</em> -
* An Array of parameters to pass the <code>onReverseComplete</code> function. For example,
* <code>new TimelineLite({onReverseComplete:myFunction, onReverseCompleteParams:["param1", "param2"]});</code>
* To self-reference the timeline instance itself in one of the parameters, use <code>"{self}"</code>,
* like: <code>onReverseCompleteParams:["{self}", "param2"]</code></li>
*
* <li><strong> autoRemoveChildren </strong>:<em> Boolean</em> -
* If <code>autoRemoveChildren</code> is set to <code>true</code>, as soon as child
* tweens/timelines complete, they will automatically get killed/removed. This is normally
* undesireable because it prevents going backwards in time (like if you want to
* <code>reverse()</code> or set the <code>progress</code> lower, etc.). It can, however,
* improve speed and memory management. The root timelines use <code>autoRemoveChildren:true</code>.</li>
*
* <li><strong> smoothChildTiming </strong>:<em> Boolean</em> -
* Controls whether or not child tweens/timelines are repositioned automatically
* (changing their <code>startTime</code>) in order to maintain smooth playback when
* properties are changed on-the-fly. For example, imagine that the timeline's playhead is
* on a child tween that is 75% complete, moving mc.x from 0 to 100 and then that tween's
* <code>reverse()</code> method is called. If <code>smoothChildTiming</code> is <code>false</code>
* (the default except for the root timelines), the tween would flip in place, keeping its
* <code>startTime</code> consistent. Therefore the playhead of the timeline would now be
* at the tween's 25% completion point instead of 75%. Remember, the timeline's playhead
* position and direction are unaffected by child tween/timeline changes. mc.x would jump
* from 75 to 25, but the tween's position in the timeline would remain consistent. However,
* if <code>smoothChildTiming</code> is <code>true</code>, that child tween's
* <code>startTime</code> would be adjusted so that the timeline's playhead intersects
* with the same spot on the tween (75% complete) as it had immediately before
* <code>reverse()</code> was called, thus playback appears perfectly smooth. mc.x
* would still be 75 and it would continue from there as the playhead moves on, but
* since the tween is reversed now mc.x will travel back towards 0 instead of 100.
* Ultimately it's a decision between prioritizing smooth on-the-fly playback
* (<code>true</code>) or consistent position(s) of child tweens/timelines
* (<code>false</code>).
*
* Some examples of on-the-fly changes to child tweens/timelines that could cause their
* <code>startTime</code> to change when <code>smoothChildTiming</code> is <code>true</code>
* are: <code>reversed, timeScale, progress, totalProgress, time, totalTime, delay, pause,
* resume, duration,</code> and <code>totalDuration</code>.</li>
*
* </ul>
*
* @example Sample code:<listing version="3.0">
//create the timeline with an onComplete callback that calls myFunction() when the timeline completes
var tl = new TimelineLite({onComplete:myFunction});
//add a tween
tl.add( new TweenLite(mc, 1, {x:200, y:100}) );
//add another tween at the end of the timeline (makes sequencing easy)
tl.add( new TweenLite(mc, 0.5, {alpha:0}) );
//append a tween using the convenience method (shorter syntax) and offset it by 0.5 seconds
tl.to(mc, 1, {rotation:30}, "+=0.5");
//reverse anytime
tl.reverse();
//Add a "spin" label 3-seconds into the timeline
tl.add("spin", 3);
//insert a rotation tween at the "spin" label (you could also define the insertion point as the time instead of a label)
tl.add( new TweenLite(mc, 2, {rotation:"360"}), "spin");
//go to the "spin" label and play the timeline from there
tl.play("spin");
//nest another TimelineLite inside your timeline...
var nested = new TimelineLite();
nested.to(mc2, 1, {x:200}));
tl.add(nested);
</listing>
*
* <p><strong>Copyright 2008-2013, GreenSock. All rights reserved.</strong> This work is subject to the terms in <a href="http://www.greensock.com/terms_of_use.html">http://www.greensock.com/terms_of_use.html</a> or for <a href="http://www.greensock.com/club/">Club GreenSock</a> members, the software agreement that was issued with the membership.</p>
*
* @author Jack Doyle, jack@greensock.com
*
**/
public class TimelineLite extends SimpleTimeline {
/** @private **/
public static const version:String = "12.0.3";
/** @private **/
protected static const _paramProps:Array = ["onStartParams","onUpdateParams","onCompleteParams","onReverseCompleteParams","onRepeatParams"];
/** @private **/
protected var _labels:Object;
/**
* Constructor.
*
* <p><strong>SPECIAL PROPERTIES</strong></p>
* <p>The following special properties may be passed in via the constructor's vars parameter, like
* <code>new TimelineLite({paused:true, onComplete:myFunction})</code></p>
*
* <ul>
* <li><strong> delay </strong>:<em> Number</em> -
* Amount of delay in seconds (or frames for frames-based tweens) before the timeline should begin.</li>
*
* <li><strong> paused </strong>:<em> Boolean</em> -
* If <code>true</code>, the timeline will pause itself immediately upon creation (by default,
* timelines automatically begin playing immediately). If you plan to create a TimelineLite and
* then populate it later (after one or more frames elapse), it is typically best to set
* <code>paused:true</code> and then <code>play()</code> after you populate it.</li>
*
* <li><strong> onComplete </strong>:<em> Function</em> -
* A function that should be called when the timeline has completed</li>
*
* <li><strong> onCompleteParams </strong>:<em> Array</em> -
* An Array of parameters to pass the <code>onComplete</code> function. For example,
* <code>new TimelineLite({onComplete:myFunction, onCompleteParams:["param1", "param2"]});</code></li>
*
* <li><strong> useFrames </strong>:<em> Boolean</em> -
* If <code>useFrames</code> is <code>true</code>, the timelines's timing will be
* based on frames instead of seconds because it is intially added to the root
* frames-based timeline. This causes both its <code>duration</code>
* and <code>delay</code> to be based on frames. An animations's timing mode is
* always determined by its parent <code>timeline</code>.</li>
*
* <li><strong> tweens </strong>:<em> Array</em> -
* To immediately insert several tweens into the timeline, use the <code>tweens</code>
* special property to pass in an Array of TweenLite/TweenMax/TimelineLite/TimelineMax
* instances. You can use this in conjunction with the <code>align</code> and
* <code>stagger</code> special properties to set up complex sequences with minimal code.
* These values simply get passed to the <code>add()</code> method.</li>
*
* <li><strong> align </strong>:<em> String</em> -
* Only used in conjunction with the <code>tweens</code> special property when multiple
* tweens are to be inserted immediately. The value simply gets passed to the
* <code>add()</code> method. The default is <code>"normal"</code>.
* Options are:
* <ul>
* <li><strong><code>"sequence"</code></strong>: aligns the tweens one-after-the-other in a sequence</li>
* <li><strong><code>"start"</code></strong>: aligns the start times of all of the tweens (ignores delays)</li>
* <li><strong><code>"normal"</code></strong>: aligns the start times of all the tweens (honors delays)</li>
* </ul>
* The <code>align</code> special property does <strong>not</strong> force all child
* tweens/timelines to maintain relative positioning, so for example, if you use
* <code>"sequence"</code> and then later change the duration of one of the nested tweens,
* it does <strong>not</strong> force all subsequent timelines to change their position.
* The <code>align</code> special property only affects the alignment of the tweens that are
* initially placed into the timeline through the <code>tweens</code> special property of
* the <code>vars</code> object.</li>
*
* <li><strong> stagger </strong>:<em> Number</em> -
* Only used in conjunction with the <code>tweens</code> special property when multiple
* tweens are to be inserted immediately. It staggers the tweens by a set amount of time
* in seconds (or in frames if <code>useFrames</code> is true). For example, if the
* stagger value is 0.5 and the "align" property is set to <code>"start"</code>, the
* second tween will start 0.5 seconds after the first one starts, then 0.5 seconds
* later the third one will start, etc. If the align property is <code>"sequence"</code>,
* there would be 0.5 seconds added between each tween. This value simply gets
* passed to the <code>add()</code> method. Default is 0.</li>
*
* <li><strong> onStart </strong>:<em> Function</em> -
* A function that should be called when the timeline begins (when its <code>time</code>
* changes from 0 to some other value which can happen more than once if the
* timeline is restarted multiple times).</li>
*
* <li><strong> onStartParams </strong>:<em> Array</em> -
* An Array of parameters to pass the <code>onStart</code> function. For example,
* <code>new TimelineLite({onStart:myFunction, onStartParams:["param1", "param2"]});</code></li>
*
* <li><strong> onUpdate </strong>:<em> Function</em> -
* A function that should be called every time the timeline updates
* (on every frame while the timeline is active)</li>
*
* <li><strong> onUpdateParams </strong>:<em> Array</em> -
* An Array of parameters to pass the <code>onUpdate</code> function. For example,
* <code>new TimelineLite({onUpdate:myFunction, onUpdateParams:["param1", "param2"]});</code></li>
*
* <li><strong> onReverseComplete </strong>:<em> Function</em> -
* A function that should be called when the timeline has reached its beginning again from the
* reverse direction. For example, if <code>reverse()</code> is called, the timeline will move
* back towards its beginning and when its <code>time</code> reaches 0, <code>onReverseComplete</code>
* will be called. This can also happen if the timeline is placed in a TimelineLite or TimelineMax
* instance that gets reversed and plays the timeline backwards to (or past) the beginning.</li>
*
* <li><strong> onReverseCompleteParams </strong>:<em> Array</em> -
* An Array of parameters to pass the <code>onReverseComplete</code> function. For example,
* <code>new TimelineLite({onReverseComplete:myFunction, onReverseCompleteParams:["param1", "param2"]});</code></li>
*
* <li><strong> autoRemoveChildren </strong>:<em> Boolean</em> -
* If <code>autoRemoveChildren</code> is set to <code>true</code>, as soon as child
* tweens/timelines complete, they will automatically get killed/removed. This is normally
* undesireable because it prevents going backwards in time (like if you want to
* <code>reverse()</code> or set the <code>progress</code> lower, etc.). It can, however,
* improve speed and memory management. The root timelines use <code>autoRemoveChildren:true</code>.</li>
*
* <li><strong> smoothChildTiming </strong>:<em> Boolean</em> -
* Controls whether or not child tweens/timelines are repositioned automatically
* (changing their <code>startTime</code>) in order to maintain smooth playback when
* properties are changed on-the-fly. For example, imagine that the timeline's playhead is
* on a child tween that is 75% complete, moving mc.x from 0 to 100 and then that tween's
* <code>reverse()</code> method is called. If <code>smoothChildTiming</code> is <code>false</code>
* (the default except for the root timelines), the tween would flip in place, keeping its
* <code>startTime</code> consistent. Therefore the playhead of the timeline would now be
* at the tween's 25% completion point instead of 75%. Remember, the timeline's playhead
* position and direction are unaffected by child tween/timeline changes. mc.x would jump
* from 75 to 25, but the tween's position in the timeline would remain consistent. However,
* if <code>smoothChildTiming</code> is <code>true</code>, that child tween's
* <code>startTime</code> would be adjusted so that the timeline's playhead intersects
* with the same spot on the tween (75% complete) as it had immediately before
* <code>reverse()</code> was called, thus playback appears perfectly smooth. mc.x
* would still be 75 and it would continue from there as the playhead moves on, but
* since the tween is reversed now mc.x will travel back towards 0 instead of 100.
* Ultimately it's a decision between prioritizing smooth on-the-fly playback
* (<code>true</code>) or consistent position(s) of child tweens/timelines
* (<code>false</code>).
*
* Some examples of on-the-fly changes to child tweens/timelines that could cause their
* <code>startTime</code> to change when <code>smoothChildTiming</code> is <code>true</code>
* are: <code>reversed, timeScale, progress, totalProgress, time, totalTime, delay, pause,
* resume, duration,</code> and <code>totalDuration</code>.</li>
*
* </ul>
*
* @param vars optionally pass in special properties like <code>onComplete, onCompleteParams, onUpdate, onUpdateParams, onStart, onStartParams, tweens, align, stagger, delay, useFrames,</code> and/or <code>autoRemoveChildren</code>.
*/
public function TimelineLite(vars:Object=null) {
super(vars);
_labels = {};
autoRemoveChildren = (this.vars.autoRemoveChildren == true);
smoothChildTiming = (this.vars.smoothChildTiming == true);
_sortChildren = true;
_onUpdate = this.vars.onUpdate;
var i:int = _paramProps.length,
j:int, a:Array;
while (--i > -1) {
if ((a = this.vars[_paramProps[i]])) {
j = a.length;
while (--j > -1) {
if (a[j] === "{self}") {
a = this.vars[_paramProps[i]] = a.concat(); //copy the array in case the user referenced the same array in multiple timelines/tweens (each {self} should be unique)
a[j] = this;
}
}
}
}
if (this.vars.tweens is Array) {
this.add(this.vars.tweens, 0, this.vars.align || "normal", this.vars.stagger || 0);
}
}
//---- START CONVENIENCE METHODS --------------------------------------
/**
* Adds a <code>TweenLite.to()</code> tween to the end of the timeline (or elsewhere using the "position" parameter)
* - this is a convenience method that accomplishes exactly the same thing as
* <code>add( TweenLite.to(...) )</code> but with less code. In other
* words, the following two lines produce identical results:
*
* <listing version="3.0">
myTimeline.add( TweenLite.to(mc, 1, {x:100, alpha:0.5}) );
myTimeline.to(mc, 1, {x:100, alpha:0.5});
</listing>
* <p>Keep in mind that you can chain these calls together and use other convenience
* methods like <code>fromTo(), call(), set(), staggerTo()</code>, etc. to build out
* sequences very quickly:</p>
*
* <listing version="3.0">
//create a timeline that calls myFunction() when it completes
var tl:TimelineLite = new TimelineLite({onComplete:myFunction});
//now we'll use chaining, but break each step onto a different line for readability...
tl.to(mc, 1, {x:100}) //tween mc.x to 100
.to(mc, 1, {y:50}, "-=0.25") //then tween mc.y to 50, starting the tween 0.25 seconds before the previous one ends
.set(mc, {alpha:0}) //then set mc.alpha to 0.5 immediately
.call(otherFunction) //then call otherFunction()
.staggerTo([mc1, mc2, mc3], 1.5, {rotation:45}, 0.25); //finally tween the rotation of mc1, mc2, and mc3 to 45 and stagger the start times by 0.25 seconds
</listing>
* <p>If you don't want to append the tween and would rather have precise control
* of the insertion point, you can use the additional <code>position</code> parameter.
* Or use a regular <code>add()</code> like
* <code>myTimeline.add( TweenLite.to(mc, 1, {x:100}), 2.75)</code>.</p>
*
* <p>The 4th parameter is the <code>position</code> which controls the placement of the
* tween in the timeline (by default, it's at the end of the timeline). Use a number to indicate
* an absolute time in terms of seconds (or frames for frames-based timelines), or you can use a string
* with a "+=" or "-=" prefix to offset the insertion point relative to the END of the timeline.
* For example, <code>"+=2"</code> would place the tween 2 seconds after the end, leaving a 2-second gap.
* <code>"-=2"</code> would create a 2-second overlap. You may also use a label like <code>"myLabel"</code>
* to have the tween inserted exactly at the label or combine a label and a relative offset like
* <code>"myLabel+=2"</code> to insert the tween 2 seconds after "myLabel" or <code>"myLabel-=3"</code>
* to insert it 3 seconds before "myLabel". If you define a label that doesn't exist yet, it
* will <strong>automatically be added to the end of the timeline</strong> before inserting the tween
* which can be quite convenient.</p>
*
* <listing version="3.0">
tl.to(mc, 1, {x:100}); //appends to the end of the timeline
tl.to(mc, 1, {x:100}, 2); //appends it at exactly 2 seconds into the timeline (absolute position)
tl.to(mc, 1, {x:100}, "+=2"); //appends it 2 seconds after the end (with a gap of 2 seconds)
tl.to(mc, 1, {x:100}, "myLabel"); //places it at "myLabel" (and if "myLabel" doesn't exist yet, it's added to the end and then the tween is inserted there)
tl.to(mc, 1, {x:100}, "myLabel+=2"); //places it 2 seconds after "myLabel"
</listing>
*
* @param target Target object (or array of objects) whose properties the tween affects
* @param duration Duration in seconds (or frames if the timeline is frames-based)
* @param vars An object defining the end value for each property that should be tweened as well as any special properties like <code>onComplete</code>, <code>ease</code>, etc. For example, to tween <code>mc.x</code> to 100 and <code>mc.y</code> to 200 and then call <code>myFunction</code>, do this: <code>myTimeline.to(mc, 1, {x:100, y:200, onComplete:myFunction})</code>.
* @param position Controls the placement of the tween in the timeline (by default, it's the end of the timeline, like "+=0"). Use a number to indicate an absolute time in terms of seconds (or frames for frames-based timelines), or you can use a string with a "+=" or "-=" prefix to offset the insertion point relative to the END of the timeline. For example, <code>"+=2"</code> would place the tween 2 seconds after the end, leaving a 2-second gap. <code>"-=2"</code> would create a 2-second overlap. You may also use a label like <code>"myLabel"</code> to have the tween inserted exactly at the label or combine a label and a relative offset like <code>"myLabel+=2"</code> to insert the tween 2 seconds after "myLabel" or <code>"myLabel-=3"</code> to insert it 3 seconds before "myLabel". If you define a label that doesn't exist yet, it will <strong>automatically be added to the end of the timeline</strong> before inserting the tween there which can be quite convenient.
* @return self (makes chaining easier)
* @see #from()
* @see #fromTo()
* @see #add()
* @see #remove()
*/
public function to(target:Object, duration:Number, vars:Object, position:*="+=0"):* {
return add( new TweenLite(target, duration, vars), position);
}
/**
* Adds a <code>TweenLite.from()</code> tween to the end of the timeline (or elsewhere using the "position" parameter)
* - this is a convenience method that accomplishes exactly the same thing as
* <code>add( TweenLite.from(...) )</code> but with less code. In other
* words, the following two lines produce identical results:
*
* <listing version="3.0">
myTimeline.add( TweenLite.from(mc, 1, {x:100, alpha:0.5}) );
myTimeline.from(mc, 1, {x:100, alpha:0.5});
</listing>
* <p>Keep in mind that you can chain these calls together and use other convenience
* methods like <code>to(), call(), set(), staggerTo()</code>, etc. to build out
* sequences very quickly:</p>
*
* <listing version="3.0">
//create a timeline that calls myFunction() when it completes
var tl:TimelineLite = new TimelineLite({onComplete:myFunction});
//now we'll use chaining, but break each step onto a different line for readability...
tl.from(mc, 1, {x:-100}) //tween mc.x from -100
.to(mc, 1, {y:50}) //then tween mc.y to 50
.set(mc, {alpha:0}) //then set mc.alpha to 0.5 immediately
.call(otherFunction) //then call otherFunction()
.staggerTo([mc1, mc2, mc3], 1.5, {rotation:45}, 0.25); //finally tween the rotation of mc1, mc2, and mc3 to 45 and stagger the start times by 0.25 seconds
</listing>
* <p>If you don't want to append the tween and would rather have precise control
* of the insertion point, you can use the additional <code>position</code> parameter.
* Or use a regular <code>add()</code> like
* <code>myTimeline.add( TweenLite.from(mc, 1, {x:100}), 2.75)</code>.</p>
*
* <p>The 4th parameter is the <code>position</code> which controls the placement of the
* tween in the timeline (by default, it's at the end of the timeline). Use a number to indicate
* an absolute time in terms of seconds (or frames for frames-based timelines), or you can use a string
* with a "+=" or "-=" prefix to offset the insertion point relative to the END of the timeline.
* For example, <code>"+=2"</code> would place the tween 2 seconds after the end, leaving a 2-second gap.
* <code>"-=2"</code> would create a 2-second overlap. You may also use a label like <code>"myLabel"</code>
* to have the tween inserted exactly at the label or combine a label and a relative offset like
* <code>"myLabel+=2"</code> to insert the tween 2 seconds after "myLabel" or <code>"myLabel-=3"</code>
* to insert it 3 seconds before "myLabel". If you define a label that doesn't exist yet, it
* will <strong>automatically be added to the end of the timeline</strong> before inserting the tween
* there which can be quite convenient.</p>
*
* <listing version="3.0">
tl.from(mc, 1, {x:100}); //appends to the end of the timeline
tl.from(mc, 1, {x:100}, 2); //appends it at exactly 2 seconds into the timeline (absolute position)
tl.from(mc, 1, {x:100}, "+=2"); //appends it 2 seconds after the end (with a gap of 2 seconds)
tl.from(mc, 1, {x:100}, "myLabel"); //places it at "myLabel" (and if "myLabel" doesn't exist yet, it's added to the end and then the tween is inserted there)
tl.from(mc, 1, {x:100}, "myLabel+=2"); //places it 2 seconds after "myLabel"
</listing>
*
* <p><strong>NOTE:</strong> By default, <code>immediateRender</code> is <code>true</code> in
* <code>from()</code> tweens, meaning that they immediately render their starting state
* regardless of any delay that is specified. You can override this behavior by passing
* <code>immediateRender:false</code> in the <code>vars</code> parameter so that it will
* wait to render until the tween actually begins.</p>
*
* @param target Target object (or array of objects) whose properties the tween affects
* @param duration Duration in seconds (or frames if the timeline is frames-based)
* @param vars An object defining the starting value for each property that should be tweened as well as any special properties like <code>onComplete</code>, <code>ease</code>, etc. For example, to tween <code>mc.x</code> from 100 and <code>mc.y</code> from 200 and then call <code>myFunction</code>, do this: <code>myTimeline.from(mc, 1, {x:100, y:200, onComplete:myFunction});</code>
* @param position Controls the placement of the tween in the timeline (by default, it's the end of the timeline, like "+=0"). Use a number to indicate an absolute time in terms of seconds (or frames for frames-based timelines), or you can use a string with a "+=" or "-=" prefix to offset the insertion point relative to the END of the timeline. For example, <code>"+=2"</code> would place the tween 2 seconds after the end, leaving a 2-second gap. <code>"-=2"</code> would create a 2-second overlap. You may also use a label like <code>"myLabel"</code> to have the tween inserted exactly at the label or combine a label and a relative offset like <code>"myLabel+=2"</code> to insert the tween 2 seconds after "myLabel" or <code>"myLabel-=3"</code> to insert it 3 seconds before "myLabel". If you define a label that doesn't exist yet, it will <strong>automatically be added to the end of the timeline</strong> before inserting the tween there which can be quite convenient.
* @return self (makes chaining easier)
* @see #to()
* @see #fromTo()
* @see #add()
* @see #remove()
*/
public function from(target:Object, duration:Number, vars:Object, position:*="+=0"):* {
return add( TweenLite.from(target, duration, vars), position);
}
/**
* Adds a <code>TweenLite.fromTo()</code> tween to the end of the timeline - this is
* a convenience method that accomplishes exactly the same thing as
* <code>add( TweenLite.fromTo(...) )</code> but with less code. In other
* words, the following two lines produce identical results:
*
* <listing version="3.0">
myTimeline.add( TweenLite.fromTo(mc, 1, {x:0, alpha:1}, {x:100, alpha:0.5}) );
myTimeline.fromTo(mc, 1, {x:0, alpha:1}, {x:100, alpha:0.5});
</listing>
* <p>Keep in mind that you can chain these calls together and use other convenience
* methods like <code>to(), call(), set(), staggerTo()</code>, etc. to build out
* sequences very quickly:</p>
*
* <listing version="3.0">
//create a timeline that calls myFunction() when it completes
var tl:TimelineLite = new TimelineLite({onComplete:myFunction});
//now we'll use chaining, but break each step onto a different line for readability...
tl.fromTo(mc, 1, {x:0}, {x:-100}) //tween mc.x from 0 to -100
.to(mc, 1, {y:50}, "-=0.25") //then tween mc.y to 50, starting it 0.25 seconds before the previous tween ends
.set(mc, {alpha:0}) //then set mc.alpha to 0.5 immediately
.call(otherFunction) //then call otherFunction()
.staggerTo([mc1, mc2, mc3], 1.5, {rotation:45}, 0.25); //finally tween the rotation of mc1, mc2, and mc3 to 45 and stagger the start times by 0.25 seconds
</listing>
* <p>If you don't want to append the tween and would rather have precise control
* of the insertion point, you can use the additional <code>position</code> parameter.
* Or use a regular <code>add()</code> like
* <code>myTimeline.add( TweenLite.fromTo(mc, 1, {x:0}, {x:100}), 2.75)</code>.</p>
*
* <p>The 4th parameter is the <code>position</code> which controls the placement of the
* tween in the timeline (by default, it's at the end of the timeline). Use a number to indicate
* an absolute time in terms of seconds (or frames for frames-based timelines), or you can use a string
* with a "+=" or "-=" prefix to offset the insertion point relative to the END of the timeline.
* For example, <code>"+=2"</code> would place the tween 2 seconds after the end, leaving a 2-second gap.
* <code>"-=2"</code> would create a 2-second overlap. You may also use a label like <code>"myLabel"</code>
* to have the tween inserted exactly at the label or combine a label and a relative offset like
* <code>"myLabel+=2"</code> to insert the tween 2 seconds after "myLabel" or <code>"myLabel-=3"</code>
* to insert it 3 seconds before "myLabel". If you define a label that doesn't exist yet, it
* will <strong>automatically be added to the end of the timeline</strong> before inserting the tween
* there which can be quite convenient.</p>
*
* <listing version="3.0">
tl.fromTo(mc, 1, {x:0}, {x:100}); //appends to the end of the timeline
tl.fromTo(mc, 1, {x:0}, {x:100}, 2); //appends it at exactly 2 seconds into the timeline (absolute position)
tl.fromTo(mc, 1, {x:0}, {x:100}, "+=2"); //appends it 2 seconds after the end (with a gap of 2 seconds)
tl.fromTo(mc, 1, {x:0}, {x:100}, "myLabel"); //places it at "myLabel" (and if "myLabel" doesn't exist yet, it's added to the end and then the tween is inserted there)
tl.fromTo(mc, 1, {x:0}, {x:100}, "myLabel+=2"); //places it 2 seconds after "myLabel"
</listing>
*
* @param target Target object (or array of objects) whose properties the tween affects
* @param duration Duration in seconds (or frames if the timeline is frames-based)
* @param fromVars An object defining the starting value for each property that should be tweened. For example, to tween <code>mc.x</code> from 100 and <code>mc.y</code> from 200, <code>fromVars</code> would look like this: <code>{x:100, y:200}</code>.
* @param toVars An object defining the end value for each property that should be tweened as well as any special properties like <code>onComplete</code>, <code>ease</code>, etc. For example, to tween <code>mc.x</code> from 0 to 100 and <code>mc.y</code> from 0 to 200 and then call <code>myFunction</code>, do this: <code>myTimeline.fromTo(mc, 1, {x:0, y:0}, {x:100, y:200, onComplete:myFunction});</code>
* @param position Controls the placement of the tween in the timeline (by default, it's the end of the timeline, like "+=0"). Use a number to indicate an absolute time in terms of seconds (or frames for frames-based timelines), or you can use a string with a "+=" or "-=" prefix to offset the insertion point relative to the END of the timeline. For example, <code>"+=2"</code> would place the tween 2 seconds after the end, leaving a 2-second gap. <code>"-=2"</code> would create a 2-second overlap. You may also use a label like <code>"myLabel"</code> to have the tween inserted exactly at the label or combine a label and a relative offset like <code>"myLabel+=2"</code> to insert the tween 2 seconds after "myLabel" or <code>"myLabel-=3"</code> to insert it 3 seconds before "myLabel". If you define a label that doesn't exist yet, it will <strong>automatically be added to the end of the timeline</strong> before inserting the tween there which can be quite convenient.
* @return self (makes chaining easier)
* @see #to()
* @see #from()
* @see #add()
* @see #remove()
*/
public function fromTo(target:Object, duration:Number, fromVars:Object, toVars:Object, position:*="+=0"):* {
return add(TweenLite.fromTo(target, duration, fromVars, toVars), position);
}
/**
* Tweens an array of targets to a common set of destination values, but staggers their
* start times by a specified amount of time, creating an evenly-spaced sequence with a
* surprisingly small amount of code. For example, let's say you have an array containing
* references to a bunch of text fields that you'd like to fall away and fade out in a
* staggered fashion with 0.2 seconds between each tween's start time:
*
* <listing version="3.0">
var textFields = [tf1, tf2, tf3, tf4, tf5];
myTimeline.staggerTo(textFields, 1, {y:"+=150", ease:Cubic.easeIn}, 0.2);
</listing>
* <p><code>staggerTo()</code> simply loops through the <code>targets</code> array and creates
* a <code>to()</code> tween for each object and then inserts it at the appropriate place on a
* new TimelineLite instance whose onComplete corresponds to the <code>onCompleteAll</code>
* (if you define one) and then appends that TimelineLite to the timeline (as a nested child).</p>
*
* <p>Note that if you define an <code>onComplete</code> (or any callback for that matter)
* in the <code>vars</code> parameter, it will be called for each tween rather than the whole
* sequence. This can be very useful, but if you want to call a function after the entire
* sequence of tweens has completed, use the <code>onCompleteAll</code> parameter (the 6th parameter).</p>
*
* <p>The 5th parameter is the <code>position</code> which controls the placement of the
* tweens in the timeline (by default, it's at the end of the timeline). Use a number to indicate
* an absolute time in terms of seconds (or frames for frames-based timelines), or you can use a string
* with a "+=" or "-=" prefix to offset the insertion point relative to the END of the timeline.
* For example, <code>"+=2"</code> would place the first tween 2 seconds after the end, leaving a 2-second gap.
* <code>"-=2"</code> would create a 2-second overlap. You may also use a label like <code>"myLabel"</code>
* to have the first tween inserted exactly at the label or combine a label and a relative offset like
* <code>"myLabel+=2"</code> to insert the first tween 2 seconds after "myLabel" or <code>"myLabel-=3"</code>
* to insert it 3 seconds before "myLabel". If you define a label that doesn't exist yet, it
* will <strong>automatically be added to the end of the timeline</strong> before inserting the tweens
* there which can be quite convenient.</p>
*
* <listing version="3.0">
tl.staggerTo(myArray, 1, {x:100}, 0.25); //appends to the end of the timeline
tl.staggerTo(myArray, 1, {x:100}, 0.25, 2); //appends at exactly 2 seconds into the timeline (absolute position)
tl.staggerTo(myArray, 1, {x:100}, 0.25, "+=2"); //appends 2 seconds after the end (with a gap of 2 seconds)
tl.staggerTo(myArray, 1, {x:100}, 0.25, "myLabel"); //places at "myLabel" (and if "myLabel" doesn't exist yet, it's added to the end and then the tweens are inserted there)
tl.staggerTo(myArray, 1, {x:100}, 0.25, "myLabel+=2"); //places 2 seconds after "myLabel"
</listing>
*
* <p><strong>JavaScript and AS2 note:</strong> - Due to the way JavaScript and AS2 don't
* maintain scope (what "<code>this</code>" refers to, or the context) in function calls,
* it can be useful to define the scope specifically. Therefore, in the JavaScript and AS2
* versions accept an extra (8th) parameter for <code>onCompleteAllScope</code>.</p>
*
* @param targets An array of target objects whose properties should be affected
* @param duration Duration in seconds (or frames if the timeline is frames-based)
* @param vars An object defining the end value for each property that should be tweened as well as any special properties like <code>ease</code>. For example, to tween <code>x</code> to 100 and <code>y</code> to 200 for mc1, mc2, and mc3, staggering their start time by 0.25 seconds and then call <code>myFunction</code> when they last one has finished, do this: <code>myTimeline.staggerTo([mc1, mc2, mc3], 1, {x:100, y:200}, 0.25, 0, null, myFunction})</code>.
* @param stagger Amount of time in seconds (or frames if the timeline is frames-based) to stagger the start time of each tween. For example, you might want to have 5 objects move down 100 pixels while fading out, and stagger the start times by 0.2 seconds - you could do: <code>myTimeline.staggerTo([mc1, mc2, mc3, mc4, mc5], 1, {y:"+=100", alpha:0}, 0.2)</code>.
* @param position Controls the placement of the first tween in the timeline (by default, it's the end of the timeline, like "+=0"). Use a number to indicate an absolute time in terms of seconds (or frames for frames-based timelines), or you can use a string with a "+=" or "-=" prefix to offset the insertion point relative to the END of the timeline. For example, <code>"+=2"</code> would place the tween 2 seconds after the end, leaving a 2-second gap. <code>"-=2"</code> would create a 2-second overlap. You may also use a label like <code>"myLabel"</code> to have the tween inserted exactly at the label or combine a label and a relative offset like <code>"myLabel+=2"</code> to insert the tween 2 seconds after "myLabel" or <code>"myLabel-=3"</code> to insert it 3 seconds before "myLabel". If you define a label that doesn't exist yet, it will <strong>automatically be added to the end of the timeline</strong> before inserting the tween there which can be quite convenient.
* @param onCompleteAll A function to call as soon as the entire sequence of tweens has completed
* @param onCompleteAllParams An array of parameters to pass the <code>onCompleteAll</code> method.
* @return self (makes chaining easier)
* @see #staggerFrom()
* @see #staggerFromTo()
*/
public function staggerTo(targets:Array, duration:Number, vars:Object, stagger:Number, position:*="+=0", onCompleteAll:Function=null, onCompleteAllParams:Array=null):* {
var tl:TimelineLite = new TimelineLite({onComplete:onCompleteAll, onCompleteParams:onCompleteAllParams});
for (var i:int = 0; i < targets.length; i++) {
if (vars.startAt != null) {
vars.startAt = _copy(vars.startAt);
}
tl.add( new TweenLite(targets[i], duration, _copy(vars)), i * stagger);
}
return add(tl, position);
}
/**
* Tweens an array of targets from a common set of destination values (using the current
* values as the destination), but staggers their start times by a specified amount of time,
* creating an evenly-spaced sequence with a surprisingly small amount of code. For example,
* let's say you have an array containing references to a bunch of text fields that you'd
* like to drop into place while fading in, all in a staggered fashion with 0.2 seconds
* between each tween's start time:
*
* <listing version="3.0">
var textFields = [tf1, tf2, tf3, tf4, tf5];
myTimeline.staggerFrom(textFields, 1, {y:"+=150"}, 0.2);
</listing>
* <p><code>staggerFrom()</code> simply loops through the <code>targets</code> array and creates
* a <code>from()</code> tween for each object and then inserts it at the appropriate place on a
* new TimelineLite instance whose onComplete corresponds to the <code>onCompleteAll</code>
* (if you define one) and then appends that TimelineLite to the timeline (as a nested child).</p>
*
* <p>Note that if you define an <code>onComplete</code> (or any callback for that matter)
* in the <code>vars</code> parameter, it will be called for each tween rather than the whole
* sequence. This can be very useful, but if you want to call a function after the entire
* sequence of tweens has completed, use the <code>onCompleteAll</code> parameter (the 6th parameter).</p>
*
* <p>The 5th parameter is the <code>position</code> which controls the placement of the
* tweens in the timeline (by default, it's at the end of the timeline). Use a number to indicate
* an absolute time in terms of seconds (or frames for frames-based timelines), or you can use a string
* with a "+=" or "-=" prefix to offset the insertion point relative to the END of the timeline.
* For example, <code>"+=2"</code> would place the first tween 2 seconds after the end, leaving a 2-second gap.
* <code>"-=2"</code> would create a 2-second overlap. You may also use a label like <code>"myLabel"</code>
* to have the first tween inserted exactly at the label or combine a label and a relative offset like
* <code>"myLabel+=2"</code> to insert the first tween 2 seconds after "myLabel" or <code>"myLabel-=3"</code>
* to insert it 3 seconds before "myLabel". If you define a label that doesn't exist yet, it
* will <strong>automatically be added to the end of the timeline</strong> before inserting the tweens
* there which can be quite convenient.</p>
*
* <listing version="3.0">
tl.staggerFrom(myArray, 1, {x:100}, 0.25); //appends to the end of the timeline
tl.staggerFrom(myArray, 1, {x:100}, 0.25, 2); //appends at exactly 2 seconds into the timeline (absolute position)
tl.staggerFrom(myArray, 1, {x:100}, 0.25, "+=2"); //appends 2 seconds after the end (with a gap of 2 seconds)
tl.staggerFrom(myArray, 1, {x:100}, 0.25, "myLabel"); //places at "myLabel" (and if "myLabel" doesn't exist yet, it's added to the end and then the tweens are inserted there)
tl.staggerFrom(myArray, 1, {x:100}, 0.25, "myLabel+=2"); //places 2 seconds after "myLabel"
</listing>
*
* <p>By default, <code>immediateRender</code> is <code>true</code> in
* <code>from()</code> tweens, meaning that they immediately render their starting state
* regardless of any delay that is specified. You can override this behavior by passing
* <code>immediateRender:false</code> in the <code>vars</code> parameter so that it will
* wait to render until the tween actually begins.</p>
*
* <p><strong>JavaScript and AS2 note:</strong> - Due to the way JavaScript and AS2 don't
* maintain scope (what "<code>this</code>" refers to, or the context) in function calls,
* it can be useful to define the scope specifically. Therefore, in the JavaScript and AS2
* versions accept an extra (8th) parameter for <code>onCompleteAllScope</code>.</p>
*
* @param targets An array of target objects whose properties should be affected
* @param duration Duration in seconds (or frames if the timeline is frames-based)
* @param vars An object defining the beginning value for each property that should be tweened as well as any special properties like <code>ease</code>. For example, to tween <code>x</code> from 100 and <code>y</code> from 200 for mc1, mc2, and mc3, staggering their start time by 0.25 seconds and then call <code>myFunction</code> when they last one has finished, do this: <code>myTimeline.staggerFrom([mc1, mc2, mc3], 1, {x:100, y:200}, 0.25, 0, null, myFunction})</code>.
* @param stagger Amount of time in seconds (or frames if the timeline is frames-based) to stagger the start time of each tween. For example, you might want to have 5 objects move down 100 pixels while fading out, and stagger the start times by 0.2 seconds - you could do: <code>myTimeline.staggerTo([mc1, mc2, mc3, mc4, mc5], 1, {y:"+=100", alpha:0}, 0.2)</code>.
* @param position Controls the placement of the first tween in the timeline (by default, it's the end of the timeline, like "+=0"). Use a number to indicate an absolute time in terms of seconds (or frames for frames-based timelines), or you can use a string with a "+=" or "-=" prefix to offset the insertion point relative to the END of the timeline. For example, <code>"+=2"</code> would place the tween 2 seconds after the end, leaving a 2-second gap. <code>"-=2"</code> would create a 2-second overlap. You may also use a label like <code>"myLabel"</code> to have the tween inserted exactly at the label or combine a label and a relative offset like <code>"myLabel+=2"</code> to insert the tween 2 seconds after "myLabel" or <code>"myLabel-=3"</code> to insert it 3 seconds before "myLabel". If you define a label that doesn't exist yet, it will <strong>automatically be added to the end of the timeline</strong> before inserting the tween there which can be quite convenient.
* @param onCompleteAll A function to call as soon as the entire sequence of tweens has completed
* @param onCompleteAllParams An array of parameters to pass the <code>onCompleteAll</code> method.
* @return self (makes chaining easier)
* @see #staggerTo()
* @see #staggerFromTo()
*/
public function staggerFrom(targets:Array, duration:Number, vars:Object, stagger:Number=0, position:*="+=0", onCompleteAll:Function=null, onCompleteAllParams:Array=null):* {
vars = _prepVars(vars);
if (!("immediateRender" in vars)) {
vars.immediateRender = true;
}
vars.runBackwards = true;
return staggerTo(targets, duration, vars, stagger, position, onCompleteAll, onCompleteAllParams);
}
/**
* Tweens an array of targets from and to a common set of values, but staggers their
* start times by a specified amount of time, creating an evenly-spaced sequence with a
* surprisingly small amount of code. For example, let's say you have an array containing
* references to a bunch of text fields that you'd like to fade from alpha:1 to alpha:0 in a
* staggered fashion with 0.2 seconds between each tween's start time:
*
* <listing version="3.0">
var textFields = [tf1, tf2, tf3, tf4, tf5];
myTimeline.staggerFromTo(textFields, 1, {alpha:1}, {alpha:0}, 0.2);
</listing>
* <p><code>staggerFromTo()</code> simply loops through the <code>targets</code> array and creates
* a <code>fromTo()</code> tween for each object and then inserts it at the appropriate place on
* a new TimelineLite instance whose onComplete corresponds to the <code>onCompleteAll</code>
* (if you define one) and then appends that TimelineLite to the timeline (as a nested child).</p>
*
* <p>Note that if you define an <code>onComplete</code> (or any callback for that matter)
* in the <code>vars</code> parameter, it will be called for each tween rather than the whole
* sequence. This can be very useful, but if you want to call a function after the entire
* sequence of tweens has completed, use the <code>onCompleteAll</code> parameter (the 7th parameter).</p>
*
* <p>The 6th parameter is the <code>position</code> which controls the placement of the
* tweens in the timeline (by default, it's at the end of the timeline). Use a number to indicate
* an absolute time in terms of seconds (or frames for frames-based timelines), or you can use a string
* with a "+=" or "-=" prefix to offset the insertion point relative to the END of the timeline.
* For example, <code>"+=2"</code> would place the first tween 2 seconds after the end, leaving a 2-second gap.
* <code>"-=2"</code> would create a 2-second overlap. You may also use a label like <code>"myLabel"</code>
* to have the first tween inserted exactly at the label or combine a label and a relative offset like
* <code>"myLabel+=2"</code> to insert the first tween 2 seconds after "myLabel" or <code>"myLabel-=3"</code>
* to insert it 3 seconds before "myLabel". If you define a label that doesn't exist yet, it
* will <strong>automatically be added to the end of the timeline</strong> before inserting the tweens
* there which can be quite convenient.</p>
*
* <listing version="3.0">
tl.staggerFromTo(myArray, 1, {x:0}, {x:100}, 0.25); //appends to the end of the timeline
tl.staggerFromTo(myArray, 1, {x:0}, {x:100}, 0.25, 2); //appends at exactly 2 seconds into the timeline (absolute position)
tl.staggerFromTo(myArray, 1, {x:0}, {x:100}, 0.25, "+=2"); //appends 2 seconds after the end (with a gap of 2 seconds)
tl.staggerFromTo(myArray, 1, {x:0}, {x:100}, 0.25, "myLabel"); //places at "myLabel" (and if "myLabel" doesn't exist yet, it's added to the end and then the tweens are inserted there)
tl.staggerFromTo(myArray, 1, {x:0}, {x:100}, 0.25, "myLabel+=2"); //places 2 seconds after "myLabel"
</listing>
*
* <p><strong>JavaScript and AS2 note:</strong> - Due to the way JavaScript and AS2 don't
* maintain scope (what "<code>this</code>" refers to, or the context) in function calls,
* it can be useful to define the scope specifically. Therefore, in the JavaScript and AS2
* versions accept an extra (9th) parameter for <code>onCompleteAllScope</code>.</p>
*
* @param targets An array of target objects whose properties should be affected
* @param duration Duration in seconds (or frames if the timeline is frames-based)
* @param fromVars An object defining the starting value for each property that should be tweened. For example, to tween <code>x</code> from 100 and <code>y</code> from 200, <code>fromVars</code> would look like this: <code>{x:100, y:200}</code>.
* @param toVars An object defining the end value for each property that should be tweened as well as any special properties like <code>ease</code>. For example, to tween <code>x</code> from 0 to 100 and <code>y</code> from 0 to 200, staggering the start times by 0.2 seconds and then call <code>myFunction</code> when they all complete, do this: <code>myTimeline.staggerFromTo([mc1, mc2, mc3], 1, {x:0, y:0}, {x:100, y:200}, 0.2, 0, null, myFunction});</code>
* @param stagger Amount of time in seconds (or frames if the timeline is frames-based) to stagger the start time of each tween. For example, you might want to have 5 objects move down 100 pixels while fading out, and stagger the start times by 0.2 seconds - you could do: <code>myTimeline.staggerTo([mc1, mc2, mc3, mc4, mc5], 1, {y:"+=100", alpha:0}, 0.2)</code>.
* @param position Controls the placement of the first tween in the timeline (by default, it's the end of the timeline, like "+=0"). Use a number to indicate an absolute time in terms of seconds (or frames for frames-based timelines), or you can use a string with a "+=" or "-=" prefix to offset the insertion point relative to the END of the timeline. For example, <code>"+=2"</code> would place the tween 2 seconds after the end, leaving a 2-second gap. <code>"-=2"</code> would create a 2-second overlap. You may also use a label like <code>"myLabel"</code> to have the tween inserted exactly at the label or combine a label and a relative offset like <code>"myLabel+=2"</code> to insert the tween 2 seconds after "myLabel" or <code>"myLabel-=3"</code> to insert it 3 seconds before "myLabel". If you define a label that doesn't exist yet, it will <strong>automatically be added to the end of the timeline</strong> before inserting the tween there which can be quite convenient.
* @param onCompleteAll A function to call as soon as the entire sequence of tweens has completed
* @param onCompleteAllParams An array of parameters to pass the <code>onCompleteAll</code> method.
* @return self (makes chaining easier)
* @see #staggerTo()
* @see #staggerFrom()
*/
public function staggerFromTo(targets:Array, duration:Number, fromVars:Object, toVars:Object, stagger:Number=0, position:*="+=0", onCompleteAll:Function=null, onCompleteAllParams:Array=null):* {
toVars = _prepVars(toVars);
fromVars = _prepVars(fromVars);
toVars.startAt = fromVars;
toVars.immediateRender = (toVars.immediateRender != false && fromVars.immediateRender != false);
return staggerTo(targets, duration, toVars, stagger, position, onCompleteAll, onCompleteAllParams);
}
/**
* Adds a callback to the end of the timeline (or elsewhere using the "position" parameter)
* - this is a convenience method that accomplishes exactly the same thing as
* <code>add( TweenLite.delayedCall(...) )</code> but with less code. In other
* words, the following two lines produce identical results:
*
* <listing version="3.0">
myTimeline.add( TweenLite.delayedCall(0, myFunction, ["param1", "param2"]) );
myTimeline.call(myFunction, ["param1", "param2"]);
</listing>
* <p>This is different than using the <code>onComplete</code> special property
* on the TimelineLite itself because once you append the callback, it stays in
* place whereas an <code>onComplete</code> is always called at the very end of
* the timeline. For example, if a timeline is populated with a 1-second tween and
* then you <code>call(myFunction)</code>, it is placed at the 1-second spot. Then
* if you append another 1-second tween, the timeline's duration will now be 2 seconds
* but the myFunction callback will still be called at the 1-second spot. An
* <code>onComplete</code> would be called at the end (2 seconds).</p>
*
* <p>Keep in mind that you can chain these calls together and use other convenience
* methods like <code>to(), fromTo(), set(), staggerTo()</code>, etc. to build out
* sequences very quickly:</p>
*
* <listing version="3.0">
//create a timeline that calls myFunction() when it completes
var tl:TimelineLite = new TimelineLite({onComplete:myFunction});
//now we'll use chaining, but break each step onto a different line for readability...
tl.to(mc, 1, {x:100}) //tween mc.x to 100
.call(myCallback) //then call myCallback()
.set(mc, {alpha:0}) //then set mc.alpha to 0.5 immediately
.call(otherFunction, ["param1", "param2"]) //then call otherFunction("param1", "param2")
.staggerTo([mc1, mc2, mc3], 1.5, {rotation:45}, 0.25); //finally tween the rotation of mc1, mc2, and mc3 to 45 and stagger the start times by 0.25 seconds
</listing>
*
* <p>The 3rd parameter is the <code>position</code> which controls the placement of the
* tween in the timeline (by default, it's at the end of the timeline). Use a number to indicate
* an absolute time in terms of seconds (or frames for frames-based timelines), or you can use a string
* with a "+=" or "-=" prefix to offset the insertion point relative to the END of the timeline.
* For example, <code>"+=2"</code> would place the tween 2 seconds after the end, leaving a 2-second gap.
* <code>"-=2"</code> would create a 2-second overlap. You may also use a label like <code>"myLabel"</code>
* to have the tween inserted exactly at the label or combine a label and a relative offset like
* <code>"myLabel+=2"</code> to insert the tween 2 seconds after "myLabel" or <code>"myLabel-=3"</code>
* to insert it 3 seconds before "myLabel". If you define a label that doesn't exist yet, it
* will <strong>automatically be added to the end of the timeline</strong> before inserting the tween
* which can be quite convenient.</p>
*
* <listing version="3.0">
tl.call(func, ["param1"]); //appends to the end of the timeline
tl.call(func, ["param1"], 2); //appends it at exactly 2 seconds into the timeline (absolute position)
tl.call(func, ["param1"], "+=2"); //appends it 2 seconds after the end (with a gap of 2 seconds)
tl.call(func, ["param1"], "myLabel"); //places it at "myLabel" (and if "myLabel" doesn't exist yet, it's added to the end and then the tween is inserted there)
tl.call(func, ["param1"], "myLabel+=2"); //places it 2 seconds after "myLabel"
</listing>
*
* <p><strong>JavaScript and AS2 note:</strong> - Due to the way JavaScript and AS2 don't
* maintain scope (what "<code>this</code>" refers to, or the context) in function calls,
* it can be useful to define the scope specifically. Therefore, in the JavaScript and AS2
* versions the 3rd parameter is <code>scope</code>, but that parameter is omitted in the AS3 version.</p>
*
* @param callback Function to call
* @param params An Array of parameters to pass the function.
* @param position Controls the placement of the callback in the timeline (by default, it's the end of the timeline, like "+=0"). Use a number to indicate an absolute time in terms of seconds (or frames for frames-based timelines), or you can use a string with a "+=" or "-=" prefix to offset the insertion point relative to the END of the timeline. For example, <code>"+=2"</code> would place the callback 2 seconds after the end, leaving a 2-second gap. <code>"-=2"</code> would create a 2-second overlap. You may also use a label like <code>"myLabel"</code> to have the callback inserted exactly at the label or combine a label and a relative offset like <code>"myLabel+=2"</code> to insert the callback 2 seconds after "myLabel" or <code>"myLabel-=3"</code> to insert it 3 seconds before "myLabel". If you define a label that doesn't exist yet, it will <strong>automatically be added to the end of the timeline</strong> before inserting the callback there which can be quite convenient.
* @return self (makes chaining easier)
* @see #add()
* @see #remove()
*/
public function call(callback:Function, params:Array=null, position:*="+=0"):* {
return add( TweenLite.delayedCall(0, callback, params), position);
}
/**
* Adds a zero-duration tween to the end of the timeline (or elsewhere using the "position" parameter)
* that sets values immediately (when the virtual playhead reaches that position
* on the timeline) - this is a convenience method that accomplishes exactly
* the same thing as <code>add( TweenLite.to(target, 0, {...}) )</code> but
* with less code. In other words, the following two lines produce identical results:
*
* <listing version="3.0">
myTimeline.add( TweenLite.to(mc, 0, {x:100, alpha:0.5, immediateRender:false}) );
myTimeline.set(mc, {x:100, alpha:0.5});
</listing>
* <p>Keep in mind that you can chain these calls together and use other convenience
* methods like <code>to(), call(), fromTo(), staggerTo()</code>, etc. to build out
* sequences very quickly:</p>
*
* <listing version="3.0">
//create a timeline that calls myFunction() when it completes
var tl:TimelineLite = new TimelineLite({onComplete:myFunction});
//now we'll use chaining, but break each step onto a different line for readability...
tl.to(mc, 1, {x:100}) //tween mc.x to 100
.set(mc, {alpha:0}) //then set mc.alpha to 0.5 immediately
.to(mc, 1, {y:50}) //then tween mc.y to 50
.call(otherFunction) //then call otherFunction()
.staggerTo([mc1, mc2, mc3], 1.5, {rotation:45}, 0.25); //finally tween the rotation of mc1, mc2, and mc3 to 45 and stagger the start times by 0.25 seconds
</listing>
* <p>The 3rd parameter is the <code>position</code> which controls the placement of the
* tween in the timeline (by default, it's at the end of the timeline). Use a number to indicate
* an absolute time in terms of seconds (or frames for frames-based timelines), or you can use a string
* with a "+=" or "-=" prefix to offset the insertion point relative to the END of the timeline.
* For example, <code>"+=2"</code> would place the tween 2 seconds after the end, leaving a 2-second gap.
* <code>"-=2"</code> would create a 2-second overlap. You may also use a label like <code>"myLabel"</code>
* to have the tween inserted exactly at the label or combine a label and a relative offset like
* <code>"myLabel+=2"</code> to insert the tween 2 seconds after "myLabel" or <code>"myLabel-=3"</code>
* to insert it 3 seconds before "myLabel". If you define a label that doesn't exist yet, it
* will <strong>automatically be added to the end of the timeline</strong> before inserting the tween
* there which can be quite convenient.</p>
*
* <listing version="3.0">
tl.set(mc, {x:100}); //appends to the end of the timeline
tl.set(mc, {x:100}, 2); //appends it at exactly 2 seconds into the timeline (absolute position)
tl.set(mc, {x:100}, "+=2"); //appends it 2 seconds after the end (with a gap of 2 seconds)
tl.set(mc, {x:100}, "myLabel"); //places it at "myLabel" (and if "myLabel" doesn't exist yet, it's added to the end and then the tween is inserted there)
tl.set(mc, {x:100}, "myLabel+=2"); //places it 2 seconds after "myLabel"
</listing>
*
* @param target Target object (or array of objects) whose properties will be set.
* @param vars An object defining the value to which each property should be set. For example, to set <code>mc.x</code> to 100 and <code>mc.y</code> to 200, do this: <code>myTimeline.set(mc, {x:100, y:200});</code>
* @param position Controls the placement of the zero-duration tween in the timeline (by default, it's the end of the timeline, like "+=0"). Use a number to indicate an absolute time in terms of seconds (or frames for frames-based timelines), or you can use a string with a "+=" or "-=" prefix to offset the insertion point relative to the END of the timeline. For example, <code>"+=2"</code> would place the tween 2 seconds after the end, leaving a 2-second gap. <code>"-=2"</code> would create a 2-second overlap. You may also use a label like <code>"myLabel"</code> to have the tween inserted exactly at the label or combine a label and a relative offset like <code>"myLabel+=2"</code> to insert the tween 2 seconds after "myLabel" or <code>"myLabel-=3"</code> to insert it 3 seconds before "myLabel". If you define a label that doesn't exist yet, it will <strong>automatically be added to the end of the timeline</strong> before inserting the tween there which can be quite convenient.
* @return self (makes chaining easier)
* @see #to()
* @see #add()
* @see #remove()
*/
public function set(target:Object, vars:Object, position:*="+=0"):* {
position = _parseTimeOrLabel(position, 0, true);
vars = _prepVars(vars);
if (vars.immediateRender == null) {
vars.immediateRender = (position === _time && !_paused);
}
return add( new TweenLite(target, 0, vars), position);
}
/** @private **/
protected static function _prepVars(vars:Object):Object { //to accommodate TweenLiteVars and TweenMaxVars instances for strong data typing and code hinting
return (vars._isGSVars) ? vars.vars : vars;
}
/** @private **/
protected static function _copy(vars:Object):Object {
var copy:Object = {}, p:String;
for (p in vars) {
copy[p] = vars[p];
}
return copy;
}