1 Reply Latest reply on May 5, 2006 12:02 PM by Newsgroup_User

    Zooming In and Out

    flying_scott Level 1
      Well, I know I am a novice, but my problem seems so simple and yet... it doesn't work.

      Check this code out:

      onLoad = function () {
      mcChart._xscale = 25;
      mcChart._yscale = 25;
      };

      function doScaleUp() {
      mcChart.onEnterFrame = function() {
      if (mcChart._yscale<=300 && mcChart._xscale<=300) {
      mcChart._yscale += 5;
      mcChart._xscale += 5;
      }
      };

      }

      function doScaleDown() {
      if (full == true) {
      mcChart.onEnterFrame = function() {
      if (mcChart._yscale>=25 && mcChart._xscale>=25) {
      mcChart._yscale -= 5;
      mcChart._xscale -= 5;
      }
      };
      }
      }

      bnZoomIn.onPress = function() {
      doScaleUp();
      };


      bnZoomOut.onPress = function() {
      doScaleDown();
      };


      mcChart.onPress = function() {
      startDrag(this);
      };


      mcChart.onRelease = function() {
      stopDrag();
      };


      The zooming in part works perfect, but the zoom out does NOTHING! what the heck am I missing???

      Thanks in advance!

      SA
        • 1. Re: Zooming In and Out
          Level 7
          flying_scott,

          > Well, I know I am a novice, but my problem seems
          > so simple and yet... it doesn't work.

          Your problem doesn't work? I'm pretty sure you mean your goal
          doesn't work.

          > The zooming in part works perfect, but the zoom out
          > does NOTHING! what the heck am I missing???

          Heck, man, it doesn't do nothing. It does something -- just not what
          you expect.

          Take a look at your zoom in code:

          function doScaleUp() {
          mcChart.onEnterFrame = function() {
          if (mcChart._yscale<=300 && mcChart._xscale<=300) {
          mcChart._yscale += 5;
          mcChart._xscale += 5;
          }
          };
          }

          This set in motion a frame loop (MovieClip.onEnterFrame) that never
          ends. Sure, your clips will stop sizing bigger until width and height are
          higher than 300, but the loop continues, which burns unnecessary CPU cycles.
          Note, too, that you can (should) refer to mcChart with the "this" operator.
          Why not something like this, instead:

          function doScaleUp() {
          mcChart.onEnterFrame = function() {
          if (this._yscale<=300 && this._xscale<=300) {
          this._yscale += 5;
          this._xscale += 5;
          } else {
          delete this.onEnterFrame;
          }
          };
          }

          Now, why is your zoom out not behaving as expected? Well, you've cause
          the whole function to depend on an if statement ...

          if (full == true) { ... }

          Where is this full variable declared? I didn't see any mention of full
          in your code except here, which means full is undefined (and hence, false).
          Since the if statement never evaluates to true, the mcChart frame loop never
          occurs.


          David
          stiller (at) quip (dot) net
          Dev essays: http://www.quip.net/blog/
          "Luck is the residue of good design."