Posted By

andrewrench on 08/16/07


Tagged

actionscript easing


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

n00ge
andrewrench


Easing any attribute of any MC


 / Published in: ActionScript
 

URL: http://proto.layer51.com/d.aspx?f=1531

usage:

this.createEmptyMovieClip("a", this.getNextHighestDepth()); a.moveTo(20, 20); a.beginFill(0xFF0000, 100); a.lineTo(0, 30); a.lineTo(30, 30); a.lineTo(30, 0); a.lineTo(0, 0); a.endFill();

a.ease("height", 200); a.ease("width, 400, .8, false); a.ease("_x", 200, .1);

  1. //****************************************************************************//
  2. // Easing any attribute of any MC //
  3. // (c) Copyright 2007 All Rights Reserved //
  4. // Rishi Ishairzay [email protected] //
  5. // Created 8/01/2007 Last Modified 8/01/2007 //
  6. //****************************************************************************//
  7.  
  8. //t:String is target attribute to be eased
  9. //v:Float is target value of attribute
  10. //s:Float is ease amount ( > 0, < 1)
  11. //r:Boolean set to true if you want pixel snapping
  12.  
  13. //calls endEase when easing is complete
  14.  
  15. MovieClip.prototype.ease = function(t, v, s, r) {
  16. if (this["_ease_"+t] instanceof MovieClip) {
  17. this["_ease_"+t].removeMovieClip();
  18. }
  19. mc = this.createEmptyMovieClip("_ease_"+t, this.getNextHighestDepth());
  20. if (s == null) {
  21. s = .4;
  22. }
  23. mc.onEnterFrame = function() {
  24. if (d == null) {
  25. d = this._parent[t];
  26. }
  27. this._parent[t] += (v-this._parent[t])*s;
  28. if (r) {
  29. this._parent[t] = Math.round(this._parent[t]);
  30. }
  31. if (Math.abs(this._parent[t]-d)<.05) {
  32. this._parent[t] = v;
  33. this._parent.endEase(t);
  34. delete this.onEnterFrame;
  35. this.removeMovieClip();
  36. }
  37. };
  38. };

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: the_coder on August 17, 2007

Genius! Works perfectly

You need to login to post a comment.