5 Replies Latest reply on Jan 29, 2007 8:41 AM by kglad

    onMouseWheel and scaling performance

    cjorata
      Hi there

      i've a mc containing a bitmap (Dim. aprox 1500 x 1000) and the onMouseWheel event linked to this mc :

      it's a thing like

      Mouse.onMouseWheel = function(delta){
      if ( checkthatthemouseisoverthemaskedarea ){
      this._xscale += delta;
      this._yscale += delta;
      }
      }

      ... this bitmap is draggable, with a masked area, so the user can drag the bitmap around and zoom in and out.

      After i zoomed in and out the image for like, 8 times or few more, i noticed that the movie started to run really slow .... it seemed like there on every zoom was created some more task in background ....

      The onMouseWheel function does nothing but zooming the image, it doesn't fire other functions ....

      Any suggestion ?
        • 1. Re: onMouseWheel and scaling performance
          kglad Adobe Community Professional & MVP
          that should be a mouse listener that has the onMouseWheel method, not the mouse class.
          • 2. Re: onMouseWheel and scaling performance
            cjorata Level 1


            Yes in fact the code was

            var listenerRotella = new Object();
            listenerRotella.onMouseWheel = function(delta) {
            bitmap._xscale += delta;
            bitmap._yscale += delta;
            }
            Mouse.addListener(listenerRotella);
            • 3. Re: onMouseWheel and scaling performance
              kglad Adobe Community Professional & MVP
              ok, and bitmap is the instance name of a movieclip, correct? if so, what other code do you have that's executing when bitmap is scaled?
              • 4. Re: onMouseWheel and scaling performance
                cjorata Level 1
                Hi there !

                I guess i solved the problem, so i want to share the solution ...

                as you see below in the event handler first i change the scale of the bitmap movieclip, and after there was a piece of code (which i removed from the previous post) redrawing a rectangle-shaped cursor proportionally to the bitmap scale :

                Mouse.onMouseWheel = function(delta){
                if ( checkthatthemouseisoverthemaskedarea ){
                this._xscale += delta;
                this._yscale += delta;

                var newScale = (_root.visore_start_width / mask_visore.plan_holder._width * mappa_holder._width) / _root.largC * 100;

                cursore_mappa._xscale = newScale;
                cursore_mappa._yscale = newScale;

                // ridisegna il cursore

                cursore_mappa.beginFill("0xFFFFFF",0);
                cursore_mappa.moveTo(0,0);
                cursore_mappa.lineTo(_root.largC,0);
                cursore_mappa.lineTo(_root.largC,_root.heightC);
                cursore_mappa.lineTo(0,_root.heightC);
                cursore_mappa.lineTo(0,0);
                cursore_mappa.endFill();

                cursore_mappa.lineStyle(0.05,0xAB0534,100,false);
                cursore_mappa.moveTo(0,0);
                cursore_mappa.lineTo(_root.largC,0);
                cursore_mappa.lineTo(_root.largC,_root.heightC);
                cursore_mappa.lineTo(0,_root.heightC);
                cursore_mappa.lineTo(0,0);

                }
                }

                The mistake was that in every scale change (every time the event handler was called) i repainted the new rectangle graphic over the old one. I tought that flash was smart enough to discard information about the old graphic, but i was wrong ... so, to make a long story short i've put

                cursore_mappa.clear();

                before the code that repaints it, and all worked perfectly !!

                Thank you anyway
                • 5. Re: onMouseWheel and scaling performance
                  kglad Adobe Community Professional & MVP
                  you're welcome.