flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [3/3] git commit: JS side of Timer and app
Date Mon, 25 Mar 2013 19:40:01 GMT
JS side of Timer and app


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/146dc0ac
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/146dc0ac
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/146dc0ac

Branch: refs/heads/develop
Commit: 146dc0ac49c656a944bdc80b3adf029e2bfc456a
Parents: fa1a15a
Author: Alex Harui <aharui@apache.org>
Authored: Mon Mar 25 12:39:20 2013 -0700
Committer: Alex Harui <aharui@apache.org>
Committed: Mon Mar 25 12:39:20 2013 -0700

----------------------------------------------------------------------
 .../src/org/apache/flex/events/EventDispatcher.js  |   22 ++
 .../js/FlexJS/src/org/apache/flex/utils/Timer.js   |  157 +++++++++++++++
 2 files changed, 179 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/146dc0ac/frameworks/js/FlexJS/src/org/apache/flex/events/EventDispatcher.js
----------------------------------------------------------------------
diff --git a/frameworks/js/FlexJS/src/org/apache/flex/events/EventDispatcher.js b/frameworks/js/FlexJS/src/org/apache/flex/events/EventDispatcher.js
index dba2c3c..b686db2 100644
--- a/frameworks/js/FlexJS/src/org/apache/flex/events/EventDispatcher.js
+++ b/frameworks/js/FlexJS/src/org/apache/flex/events/EventDispatcher.js
@@ -47,6 +47,28 @@ org.apache.flex.events.EventDispatcher.prototype.addEventListener = function(typ
 
 /**
  * @this {org.apache.flex.events.EventDispatcher}
+ * @param {string} type The event type.
+ * @param {function(?): ?} fn The event handler.
+ */
+org.apache.flex.events.EventDispatcher.prototype.removeEventListener = function(type, fn)
{
+    if (!this.listeners_.type) {
+        return;
+    }
+
+    var listeners = this.listeners_[type];
+    var n = listeners.length;
+    for (var i = 0; i < n; i++)
+    {
+        if (fn == listeners[i])
+        {
+            listeners.splice(i, 1);
+            break;
+        }
+    }
+};
+
+/**
+ * @this {org.apache.flex.events.EventDispatcher}
  * @param {Object} event The event to dispatch.
  */
 org.apache.flex.events.EventDispatcher.prototype.dispatchEvent = function(event) {

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/146dc0ac/frameworks/js/FlexJS/src/org/apache/flex/utils/Timer.js
----------------------------------------------------------------------
diff --git a/frameworks/js/FlexJS/src/org/apache/flex/utils/Timer.js b/frameworks/js/FlexJS/src/org/apache/flex/utils/Timer.js
new file mode 100644
index 0000000..ca18e8e
--- /dev/null
+++ b/frameworks/js/FlexJS/src/org/apache/flex/utils/Timer.js
@@ -0,0 +1,157 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+goog.provide('org.apache.flex.utils.Timer');
+
+goog.require('org.apache.flex.FlexGlobal');
+goog.require('org.apache.flex.events.EventDispatcher');
+
+/**
+ * @constructor
+ * @extends {org.apache.flex.events.EventDispatcher}
+ */
+org.apache.flex.utils.Timer = function(delay, repeatCount) {
+    org.apache.flex.events.EventDispatcher.call(this);
+    
+    
+    /**
+     * @private
+     * @type {number}
+     */
+    this.timerInterval = -1;
+
+    /**
+     * @private
+     * @type {number}
+     */
+    this._delay = delay;
+    
+    /**
+     * @private
+     * @type {number}
+     */
+    this._currentCount = 0;
+    
+
+    if (typeof(repeatCount) != 'undefined') 
+    { 
+        this._repeatCount = repeatCount;
+    }
+
+};
+goog.inherits(org.apache.flex.utils.Timer,
+                org.apache.flex.events.EventDispatcher);
+
+/**
+ * @expose
+ * @this {org.apache.flex.utils.Timer}
+ * Stops the timer and sets currentCount = 0.
+ */
+org.apache.flex.utils.Timer.prototype.reset = function() {
+    this.stop();
+    this._currentCount = 0;
+};
+
+/**
+ * @expose
+ * @this {org.apache.flex.utils.Timer}
+ * Stops the timer.
+ */
+org.apache.flex.utils.Timer.prototype.stop =
+                                function() {
+    clearInterval(this.timerInterval);
+    this.timerInterval = -1;
+};
+
+/**
+ * @expose
+ * @this {org.apache.flex.utils.Timer}
+ * Starts the timer.
+ */
+org.apache.flex.utils.Timer.prototype.start =
+                                function() {
+    this.timerInterval = setInterval(org.apache.flex.FlexGlobal.createProxy     
+        (this, this.timerHandler),
+        this._delay);
+};
+
+/**
+ * @private
+ * @this {org.apache.flex.utils.Timer}
+ */
+org.apache.flex.utils.Timer.prototype.timerHandler =
+                                function() {
+    this._currentCount++;
+    if (this._repeatCount > 0 && this._currentCount >= this._repeatCount)
+        this.stop();
+        
+    var evt = document.createEvent('Event');
+    evt.initEvent('timer', false, false);
+    this.dispatchEvent(evt);
+    
+};
+
+/**
+ * @expose
+ * @this {org.apache.flex.utils.Timer}
+ * @returns {Number} The currentCount.
+ */
+org.apache.flex.utils.Timer.prototype.get_currentCount = function() {
+    return this._currentCount;
+};
+
+/**
+ * @expose
+ * @this {org.apache.flex.utils.Timer}
+ * @returns {boolean} True if the timer is running.
+ */
+org.apache.flex.utils.Timer.prototype.get_running = function() {
+    return this.timerInterval != -1;
+};
+
+/**
+ * @expose
+ * @this {org.apache.flex.utils.Timer}
+ * @returns {Number} The number of milliseconds between events.
+ */
+org.apache.flex.utils.Timer.prototype.get_delay = function() {
+    return this._delay;
+};
+
+/**
+ * @expose
+ * @this {org.apache.flex.utils.Timer}
+ * @param {Number} value The number of milliseconds between events.
+ */
+org.apache.flex.utils.Timer.prototype.set_delay = function(value) {
+    this._delay = value;
+};
+
+/**
+ * @expose
+ * @this {org.apache.flex.utils.Timer}
+ * @returns {Number} The repeat count.
+ */
+org.apache.flex.utils.Timer.prototype.get_repeatCount = function() {
+    return this._repeatCount;
+};
+
+/**
+ * @expose
+ * @this {org.apache.flex.utils.Timer}
+ * @param {Number} value The repeat count.
+ */
+org.apache.flex.utils.Timer.prototype.set_repeatCount = function(value) {
+    this._repeatCount = value;
+};


Mime
View raw message