2007/11/22 | Tween1.0.as 简陋的缓动类AS1.0版本
类别(Flash习作) | 评论(1) | 阅读(113) | 发表于 23:29
//Tween类AS1.0版本
/*用例:
#include "Tween1.0.as"
var myTween=new Tween();
myTween.addTween(MC1,"_x",func1,0,200);
function func1(obj){
 obj._x+=5;
}
myTween.addTween(MC2,"_alpha",func2,100,0);
function func2(obj){
 obj._alpha-=5;
}
*/
function Tween() {
 _global.Tween_intervalID1 = null;
 _global.Tween_instance=this;
 this.running = false;
 this.list = new Array();
}
Tween.prototype.addTween = function(obj, prop, func, begin, finish) {
 obj[prop] = begin;
 this.list.push({obj:obj, prop:prop, func:func, begin:begin, finish:finish});
 if (!this.running) {
  this.start();
 }
};
Tween.prototype.start = function() {
 _global.Tween_intervalID1 = setInterval(function () {
  _global.Tween_instance.run();
  updateAfterEvent();
 }, 0);
 this.running = true;
};
Tween.prototype.run = function() {
 if (this.list.length>0) {
  var obj, prop, func, begin, finish;
  for (var i in this.list) {
   obj = this.list[i].obj;
   prop = this.list[i].prop;
   func = this.list[i].func;
   begin = this.list[i].begin;
   finish = this.list[i].finish;
   //
   func(obj);
   if (obj[prop]>=finish) {
    obj[prop] = finish;
    this.list.splice(i, 1);
   }
  }
 } else {
  this.stop();
 }
};
Tween.prototype.stop = function() {
 clearInterval(_global.Tween_intervalID1);
 _global.Tween_intervalID1 = null;
 this.running = false;
};
3

评论Comments