Jul 31, 2009

ActionScript: fade in/out

function fadeAnimation(target,show,speed) {
 target.showing = show;
 target.speed = speed;
 if(show) target._visible = true;
 
 target.onEnterFrame = function() {
  this._alpha += (this.showing) ? +this.speed : -this.speed;  
  if(this._alpha<=0 && !this.showing) {
   this._visible = false;
   delete this.onEnterFrame;
  }
  if(this._alpha>=100 && this.showing) {
   delete this.onEnterFrame;
  }
 }
}

No comments: