Skip to content

Commit 2b4cbbc

Browse files
committed
Tween & Timeline now extend EventDispatcher. Tween waits to add itself as a listener on Ticker until the first tween starts.
Signed-off-by: Grant Skinner <info@gskinner.com>
1 parent 171bfe1 commit 2b4cbbc

File tree

8 files changed

+206
-63
lines changed

8 files changed

+206
-63
lines changed

VERSIONS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ CRITICAL (may break existing content):
2121
- fixed an issue with EventDispatcher when adding the same listener to an event twice
2222
- fixed hasActiveTweens to return a Boolean consistently
2323
- added Timeline.getLabels() & getCurrentLabel()
24+
- Tween waits to add itself as a listener on Ticker until the first tween is started
2425

2526

2627
Version 0.4.1 [May 10, 2013]

docs/TweenJS_docs-NEXT.zip

-2.37 KB
Binary file not shown.

examples/assets/easeljs-NEXT.min.js

Lines changed: 171 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/tweenjs-NEXT.min.js

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/createjs/events/Event.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ this.createjs = this.createjs||{};
5252
* @param {String} type The event type.
5353
* @param {Boolean} bubbles Indicates whether the event will bubble through the display list.
5454
* @param {Boolean} cancelable Indicates whether the default behaviour of this event can be cancelled.
55-
* @uses EventDispatcher
5655
* @constructor
5756
**/
5857
var Event = function(type, bubbles, cancelable) {

src/tweenjs/Timeline.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ this.createjs = this.createjs||{};
5353
* <LI> position: indicates the initial position for this timeline.</LI>
5454
* <LI> onChange: specifies a listener to add for the {{#crossLink "Timeline/change:event"}}{{/crossLink}} event.</LI>
5555
* </UL>
56-
* @uses EventDispatcher
56+
* @extends EventDispatcher
5757
* @constructor
5858
**/
5959
var Timeline = function(tweens, labels, props) {
6060
this.initialize(tweens, labels, props);
6161
};
62-
var p = Timeline.prototype;
62+
var p = Timeline.prototype = new createjs.EventDispatcher();
6363

6464
// public properties:
6565

@@ -109,17 +109,6 @@ var p = Timeline.prototype;
109109
* @since 0.5.0
110110
**/
111111

112-
// mix-ins:
113-
// EventDispatcher methods:
114-
p.addEventListener = null;
115-
p.removeEventListener = null;
116-
p.removeAllEventListeners = null;
117-
p.dispatchEvent = null;
118-
p.hasEventListener = null;
119-
p._listeners = null;
120-
121-
createjs.EventDispatcher.initialize(p); // inject EventDispatcher methods.
122-
123112
// private properties:
124113

125114
/**

src/tweenjs/Tween.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,13 @@ this.createjs = this.createjs||{};
120120
* </UL>
121121
* @param {Object} [pluginData] An object containing data for use by installed plugins. See individual
122122
* plugins' documentation for details.
123-
* @uses EventDispatcher
123+
* @extends EventDispatcher
124124
* @constructor
125125
*/
126126
var Tween = function(target, props, pluginData) {
127127
this.initialize(target, props, pluginData);
128128
};
129-
var p = Tween.prototype;
129+
var p = Tween.prototype = new createjs.EventDispatcher();
130130

131131
// static interface:
132132
/**
@@ -231,9 +231,6 @@ var p = Tween.prototype;
231231
}
232232
};
233233

234-
// Static initialization of Ticker.
235-
if (createjs.Ticker) { createjs.Ticker.addEventListener("tick", Tween); }
236-
237234
/**
238235
* Handle events that result from Tween being used as an event handler. This is included to allow Tween to handle
239236
* tick events from <code>createjs.Ticker</code>. No other events are handled in Tween.
@@ -324,6 +321,8 @@ var p = Tween.prototype;
324321
/**
325322
* Registers or unregisters a tween with the ticking system.
326323
* @method _register
324+
* @param {Tween} tween The tween instance to register or unregister.
325+
* @param {Boolean} value If true, the tween is registered. If false the tween is unregistered.
327326
* @static
328327
* @protected
329328
*/
@@ -334,6 +333,7 @@ var p = Tween.prototype;
334333
// TODO: this approach might fail if a dev is using sealed objects in ES5
335334
if (target) { target.tweenjs_count = target.tweenjs_count ? target.tweenjs_count+1 : 1; }
336335
tweens.push(tween);
336+
if (!Tween._inited && createjs.Ticker) { createjs.Ticker.addEventListener("tick", Tween); Tween._inited = true; }
337337
} else {
338338
if (target) { target.tweenjs_count--; }
339339
var i = tweens.length;
@@ -346,17 +346,6 @@ var p = Tween.prototype;
346346
}
347347
};
348348

349-
// mix-ins:
350-
// EventDispatcher methods:
351-
p.addEventListener = null;
352-
p.removeEventListener = null;
353-
p.removeAllEventListeners = null;
354-
p.dispatchEvent = null;
355-
p.hasEventListener = null;
356-
p._listeners = null;
357-
358-
createjs.EventDispatcher.initialize(p); // inject EventDispatcher methods.
359-
360349
// public properties:
361350
/**
362351
* Causes this tween to continue playing when a global pause is active. For example, if TweenJS is using Ticker,
@@ -522,6 +511,14 @@ var p = Tween.prototype;
522511
*/
523512
p._useTicks = false;
524513

514+
/**
515+
* @property _inited
516+
* @type {boolean}
517+
* @default false
518+
* @protected
519+
*/
520+
p._inited = false;
521+
525522
// constructor:
526523
/**
527524
* @method initialize

src/tweenjs/version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ this.createjs = this.createjs || {};
2727
* @type String
2828
* @static
2929
**/
30-
s.buildDate = /*date*/"Mon, 12 Aug 2013 16:06:01 GMT"; // injected by build process
30+
s.buildDate = /*date*/"Tue, 27 Aug 2013 17:44:21 GMT"; // injected by build process
3131

3232
})();

0 commit comments

Comments
 (0)