home *** CD-ROM | disk | FTP | other *** search
- class ds.transitions.Tween
- {
- var obj;
- var prop;
- var begin;
- var _listeners;
- var addListener;
- var prevTime;
- var _time;
- var looping;
- var _duration;
- var broadcastMessage;
- var isYoyo;
- var isFinished;
- var isPlaying;
- var _fps;
- var prevPos;
- var _pos;
- var change;
- var _intervalID;
- static var __initBeacon = mx.transitions.OnEnterFrameBeacon.init();
- static var __initBroadcaster = mx.transitions.BroadcasterMX.initialize(ds.transitions.Tween.prototype);
- function Tween($obj, $prop, $func, $begin, $finish, $duration)
- {
- mx.transitions.OnEnterFrameBeacon.init();
- this.obj = $obj;
- this.prop = $prop;
- this.begin = $begin;
- this.duration = $duration;
- if($func)
- {
- this.func = $func;
- }
- this.finish = $finish;
- this._listeners = [];
- this.addListener(this);
- if(arguments.length = 6 && this.obj != null)
- {
- this.start(this.obj[$prop] == this.begin);
- }
- }
- function set time(t)
- {
- this.prevTime = this._time;
- if(t >= this.duration)
- {
- if(this.looping)
- {
- this.rewind(t - this._duration);
- this.update();
- this.broadcastMessage("onMotionLooped",this);
- }
- else if(this.isYoyo)
- {
- this.yoyo();
- this.broadcastMessage("onMotionYoyo",this);
- }
- else
- {
- this._time = t;
- this.update();
- this.stop();
- this.isFinished = true;
- this.broadcastMessage("onMotionFinished",this);
- }
- }
- else if(t < 0)
- {
- this.rewind();
- this.update();
- }
- else
- {
- this._time = t;
- this.update();
- }
- }
- function get time()
- {
- return this._time;
- }
- function get func()
- {
- return this._func;
- }
- function set func(f)
- {
- if(f == null)
- {
- this._func = function(t, b, c, d)
- {
- return c * t / d + b;
- };
- }
- else
- {
- this._func = f;
- }
- }
- function set duration(d)
- {
- this._duration = !(d == null || d <= 0) ? d : _global.Infinity;
- }
- function get duration()
- {
- return this._duration;
- }
- function set FPS(fps)
- {
- var _loc2_ = this.isPlaying;
- this.stopEnterFrame();
- this._fps = fps;
- if(_loc2_)
- {
- this.startEnterFrame();
- }
- }
- function get FPS()
- {
- return this._fps;
- }
- function set position(p)
- {
- this.setPosition(p);
- }
- function setPosition(p)
- {
- this.prevPos = this._pos;
- if(this.prop == "_currentframe")
- {
- this._pos = Math.floor(p);
- this.obj.gotoAndStop(this._pos);
- }
- else
- {
- this.obj[this.prop] = this._pos = p;
- }
- this.broadcastMessage("onMotionChanged",this,this._pos);
- updateAfterEvent();
- }
- function get position()
- {
- return this.getPosition();
- }
- function getPosition(t)
- {
- if(t == undefined)
- {
- t = this._time;
- }
- return this.func(t,this.begin,this.change,this._duration);
- }
- function set finish(f)
- {
- this.change = f - this.begin;
- }
- function get finish()
- {
- return this.begin + this.change;
- }
- function continueTo($finish, $duration)
- {
- this.begin = this.position;
- this.finish = $finish;
- if($duration != undefined)
- {
- this.duration = $duration;
- }
- this.start(true);
- }
- function yoyo()
- {
- this.stopEnterFrame();
- this.continueTo(this.begin,this.time);
- }
- function startEnterFrame()
- {
- if(this._fps == undefined)
- {
- clearInterval(this._intervalID);
- _global.MovieClip.addListener(this);
- }
- else
- {
- _global.MovieClip.removeListener(this);
- this._intervalID = setInterval(this,"onEnterFrame",1000 / this._fps);
- }
- this.isFinished = false;
- this.isPlaying = true;
- }
- function stopEnterFrame()
- {
- if(this._fps == undefined)
- {
- _global.MovieClip.removeListener(this);
- }
- else
- {
- clearInterval(this._intervalID);
- }
- this.isPlaying = false;
- }
- function start(inPosition)
- {
- if(inPosition)
- {
- this._time = 0;
- }
- else
- {
- this.rewind();
- }
- this.startEnterFrame();
- this.broadcastMessage("onMotionStarted",this);
- }
- function stop()
- {
- this.stopEnterFrame();
- this.broadcastMessage("onMotionStopped",this);
- }
- function pause()
- {
- this.stopEnterFrame();
- this.broadcastMessage("onMotionPaused",this);
- }
- function resume()
- {
- if(this.isFinished)
- {
- return undefined;
- }
- this.startEnterFrame();
- this.broadcastMessage("onMotionResumed",this);
- }
- function rewind(t)
- {
- this._time = t != undefined ? t : 0;
- this.update();
- }
- function nextFrame()
- {
- this.time = this._time + 1;
- }
- function onEnterFrame()
- {
- this.nextFrame();
- }
- function prevFrame()
- {
- this.time = this._time - 1;
- }
- function toString()
- {
- return "[Tween]";
- }
- function update()
- {
- this.position = this.getPosition(this._time);
- }
- function _func(t, b, c, d)
- {
- return c * t / d + b;
- }
- }
-