@@ -1561,6 +1561,15 @@ this.createjs = this.createjs||{};
1561
1561
* @protected
1562
1562
*/
1563
1563
this . _inited = false ;
1564
+
1565
+ /**
1566
+ * Indicates whether the tween is currently registered with Tween.
1567
+ * @property _registered
1568
+ * @type {boolean }
1569
+ * @default false
1570
+ * @protected
1571
+ */
1572
+ this . _registered = false ;
1564
1573
1565
1574
1566
1575
if ( props ) {
@@ -1738,7 +1747,7 @@ this.createjs = this.createjs||{};
1738
1747
for ( var i = 0 , l = tweens . length ; i < l ; i ++ ) {
1739
1748
var tween = tweens [ i ] ;
1740
1749
tween . _paused = true ;
1741
- tween . target . tweenjs_count = 0 ;
1750
+ tween . target && ( tween . target . tweenjs_count = 0 ) ;
1742
1751
}
1743
1752
tweens . length = 0 ;
1744
1753
} ;
@@ -1752,7 +1761,7 @@ this.createjs = this.createjs||{};
1752
1761
* @static
1753
1762
*/
1754
1763
Tween . hasActiveTweens = function ( target ) {
1755
- if ( target ) { return target . tweenjs_count ; }
1764
+ if ( target ) { return target . tweenjs_count != null && ! ! target . tweenjs_count ; }
1756
1765
return Tween . _tweens && ! ! Tween . _tweens . length ;
1757
1766
} ;
1758
1767
@@ -1791,21 +1800,22 @@ this.createjs = this.createjs||{};
1791
1800
Tween . _register = function ( tween , value ) {
1792
1801
var target = tween . _target ;
1793
1802
var tweens = Tween . _tweens ;
1794
- if ( value ) {
1803
+ if ( value && ! tween . _registered ) {
1795
1804
// TODO: this approach might fail if a dev is using sealed objects in ES5
1796
1805
if ( target ) { target . tweenjs_count = target . tweenjs_count ? target . tweenjs_count + 1 : 1 ; }
1797
1806
tweens . push ( tween ) ;
1798
1807
if ( ! Tween . _inited && createjs . Ticker ) { createjs . Ticker . addEventListener ( "tick" , Tween ) ; Tween . _inited = true ; }
1799
- } else {
1808
+ } else if ( ! value && tween . _registered ) {
1800
1809
if ( target ) { target . tweenjs_count -- ; }
1801
1810
var i = tweens . length ;
1802
1811
while ( i -- ) {
1803
1812
if ( tweens [ i ] == tween ) {
1804
1813
tweens . splice ( i , 1 ) ;
1805
- return ;
1814
+ break ;
1806
1815
}
1807
1816
}
1808
1817
}
1818
+ tween . _registered = value ;
1809
1819
} ;
1810
1820
1811
1821
@@ -1913,7 +1923,7 @@ this.createjs = this.createjs||{};
1913
1923
/**
1914
1924
* Queues an action to pause the specified tween.
1915
1925
* @method pause
1916
- * @param {Tween } tween The tween to play . If null, it pauses this tween.
1926
+ * @param {Tween } tween The tween to pause . If null, it pauses this tween.
1917
1927
* @return {Tween } This tween instance (for chaining calls)
1918
1928
*/
1919
1929
p . pause = function ( tween ) {
@@ -2329,6 +2339,15 @@ this.createjs = this.createjs||{};
2329
2339
* @protected
2330
2340
**/
2331
2341
this . _useTicks = false ;
2342
+
2343
+ /**
2344
+ * Indicates whether the timeline is currently registered with Tween.
2345
+ * @property _registered
2346
+ * @type {boolean }
2347
+ * @default false
2348
+ * @protected
2349
+ */
2350
+ this . _registered = false ;
2332
2351
2333
2352
2334
2353
if ( props ) {
@@ -2508,8 +2527,7 @@ this.createjs = this.createjs||{};
2508
2527
* is `false`).
2509
2528
**/
2510
2529
p . setPosition = function ( value , actionsMode ) {
2511
- if ( value < 0 ) { value = 0 ; }
2512
- var t = this . loop ? value % this . duration : value ;
2530
+ var t = this . _calcPosition ( value ) ;
2513
2531
var end = ! this . loop && value >= this . duration ;
2514
2532
if ( t == this . _prevPos ) { return end ; }
2515
2533
this . _prevPosition = value ;
@@ -2529,7 +2547,7 @@ this.createjs = this.createjs||{};
2529
2547
* @param {Boolean } value Indicates whether the tween should be paused (`true`) or played (`false`).
2530
2548
**/
2531
2549
p . setPaused = function ( value ) {
2532
- this . _paused = ! ! value ;
2550
+ this . _paused = ! ! value ;
2533
2551
createjs . Tween . _register ( this , ! value ) ;
2534
2552
} ;
2535
2553
@@ -2589,13 +2607,25 @@ this.createjs = this.createjs||{};
2589
2607
// private methods:
2590
2608
/**
2591
2609
* @method _goto
2610
+ * @param {String | Number } positionOrLabel
2592
2611
* @protected
2593
2612
**/
2594
2613
p . _goto = function ( positionOrLabel ) {
2595
2614
var pos = this . resolve ( positionOrLabel ) ;
2596
2615
if ( pos != null ) { this . setPosition ( pos ) ; }
2597
2616
} ;
2598
-
2617
+
2618
+ /**
2619
+ * @method _calcPosition
2620
+ * @param {Number } value
2621
+ * @return {Number }
2622
+ * @protected
2623
+ **/
2624
+ p . _calcPosition = function ( value ) {
2625
+ if ( value < 0 ) { return 0 ; }
2626
+ if ( value < this . duration ) { return value ; }
2627
+ return this . loop ? value % this . duration : this . duration ;
2628
+ } ;
2599
2629
2600
2630
createjs . Timeline = createjs . promote ( Timeline , "EventDispatcher" ) ;
2601
2631
@@ -3368,6 +3398,6 @@ this.createjs = this.createjs || {};
3368
3398
* @type String
3369
3399
* @static
3370
3400
**/
3371
- s . buildDate = /*=date*/ "Thu, 12 Mar 2015 20:31:51 GMT" ; // injected by build process
3401
+ s . buildDate = /*=date*/ "Wed, 27 May 2015 18:12:44 GMT" ; // injected by build process
3372
3402
3373
3403
} ) ( ) ;
0 commit comments