14 Replies Latest reply on Apr 25, 2006 12:21 PM by Peter Lorent

    Making a complex button with the Tween class...not sure why this isn't working.

    robdodson Level 1
      Hi all,

      I'm trying to make a button which scales up on rollover and scales down on rollout and I wanted to use the Tween class to do it because I'm going to be making a bunch of these buttons and I want the code to be as efficient as possible.

      So right now I have a circle in a movie clip, and here's what I have on the first frame of that circle's actions layer:


      import mx.transitions.Tween;
      import mx.transitions.easing.*;

      function grow(who) {
      var tw:Tween = new Tween(who, "_xscale", Strong.easeOut, 100, 400, 1, true);
      var tw2:Tween = new Tween(who, "_yscale", Strong.easeOut, 100, 400, 1, true);
      }
      function shrink(who) {
      var tw3:Tween = new Tween(who, "_xscale", Strong.easeOut, 400, 100, 1, true);
      var tw4:Tween = new Tween(who, "_yscale", Strong.easeOut, 400, 100, 1, true);
      }

      this.onEnterFrame = function() {
      trace(rewind);
      if (rewind == true) {
      shrink(this);
      }
      };

      this.onRollOver = function() {
      rewind = false;
      grow(this);
      };

      this.onRollOut = function() {
      rewind = true;
      };


      The circle scales up just fine but when I rollout it doesn't scale back down. I did a trace to see if my tween was being called and sure enough it was. So I did another trace to see if the _xscale or _yscale was changing and they both were going down to around 290 on rollOut although there's no noticeable difference in the size of the button, it just looks like it's sitting there.

      I was also wondering if importing the whole class library will add very much to my file size?
      Also, since I'm going to have a lot of these buttons on the stage at the same time (these buttons will be like markers all over a map so there'll probably be around 50+) would it be a bad idea to have that many onEnterFrame checks running simultaneously? Is that going to slow the user's CPU way down?