10 Replies Latest reply on Oct 9, 2009 5:37 AM by Ned Murphy

    Incrimental zoom buttons (CS4)

    Gu55tav

      Hi,

       

      Im trying to script zoom in and out buttons in CS4 (Actionscript 2). I have the code sorted so they can be clicked once to zoom. I want to try and have 3 levels of zoom assigned to each button. Zo if pressing zoom up 1st press gives you 125% zoom, 2nd press 150% and 3rd press 200%. Same goes for the zoom out button but in reverse.

       

      The code im using for the buttons at present is...

       

      zoomupBtn.onRelease = function() {
      setProperty (_parent.pages, _xscale, "200");
      setProperty (_parent.pages, _yscale, "200");
      }
      zoomdownBtn.onRelease = function() {
      setProperty (_parent.pages, _xscale, "100");
      setProperty (_parent.pages, _yscale, "100");

       

      What would i need to add to get this to ork.

       

      Any help is massivley appreciated.

        • 1. Re: Incrimental zoom buttons (CS4)
          Ned Murphy Adobe Community Professional & MVP

          Try:

           

          zoomupBtn.onRelease = function() {

               if(_parent.pages._xscale < 200){

                    _parent.pages._xscale += 50;

                     _parent.pages._yscale += 50;

               }
          }
          zoomdownBtn.onRelease = function() {

               if(_parent.pages._xscale > 100){

                    _parent.pages._xscale -= 50;

                     _parent.pages._yscale -= 50;

               }

          }

          1 person found this helpful
          • 2. Re: Incrimental zoom buttons (CS4)
            Gu55tav Level 1

            Cheers for that mate.

             

            It coming back with some syntax errors but i'll have a play around with it to see if i can get it to work.

            • 3. Re: Incrimental zoom buttons (CS4)
              Gu55tav Level 1

              Ned,

               

              I was talking Rubbish. That works absolutely perfect!!

               

              You are a star!

              • 4. Re: Incrimental zoom buttons (CS4)
                Gu55tav Level 1

                Ned,

                 

                Wonder if you know how i could solve this. Its the same item.

                 

                Once zoomed the user can drag the pages around the screen but i defined bounderies so they couldnt drag past certain points. Now that i have more than one zoom level i think i need to repeat the drag script for each zoom level.

                 

                Here is the script...

                 


                pages.onMouseDown = function () {
                    // check if page is zoomed
                    if (pages._xscale != 100) {
                        Dragging = true;
                        updateCursor();
                        Mouse.hide();
                        dragCursor._visible=true;
                        startDrag(this,false, 1500,790,40,42);
                    }
                };

                 

                How would i go about this?

                • 5. Re: Incrimental zoom buttons (CS4)
                  Ned Murphy Adobe Community Professional & MVP

                  You will want to make them relative to the _width and _height properties of the object being dragged, with consideration for the registration point of the object.

                   

                  Just as an example, assuming the registration point is the top left corner:

                   

                  left = left boundary

                  top = top boudary

                  right = right boundary minus this._width

                  bottom = bottom boundary minus this._height

                   

                   

                  startDrag(this, false, left, top, right, bottom);

                  • 6. Re: Incrimental zoom buttons (CS4)
                    Gu55tav Level 1

                    Hi Ned,

                     

                    Im not sure if i worded the last question correctly.

                     

                    Is there a way that i can set the startdrag properties for each level of zoom (i dont know if i can do this with one batch of code or wether i need to repeat the code posted previously for each variable of zoom) so that the user can only drag to a certain point around the screen on each zoom level.

                     

                    The code i supplied works perfect at max zoom however when a lesser amount of zoom is applied they can drag past the limits that i would want them to.

                     

                    I have tried repeating the code for each different zoom level however this doesnt seem to work.

                     

                    Cheers

                    • 7. Re: Incrimental zoom buttons (CS4)
                      Gu55tav Level 1

                      More stuff....

                       

                      I think im close to getting this to work however I cant get the code to differenciate between levels of zoom....

                       

                      The code im using just now is:

                       

                          pages.onMouseDown = function () {
                          // check if page is zoomed
                          if (pages._xscale != 25) {
                              Dragging = true;
                              updateCursor();
                              Mouse.hide();
                              dragCursor._visible=true;
                              startDrag(this,false, 950,490,600,322);
                          }
                          }
                      pages.onMouseDown = function () {
                          // check if page is zoomed
                          if (pages._xscale != 100) {
                              Dragging = true;
                              updateCursor();
                              Mouse.hide();
                              dragCursor._visible=true;
                              startDrag(this,false, 1500,790,40,42);
                          }
                      };

                       

                      The values on the first part are correct for the 25% zoom as are the ones for 100%. When i run the movie it only uses the values in the second batch of code. How would I make it so it looks at the appropriate startdrag figures for each zoom level???

                      • 8. Re: Incrimental zoom buttons (CS4)
                        Ned Murphy Adobe Community Professional & MVP

                        I'm pretty sure I understood what you want and that I offered an approach to solving it with one piece of code.  Your variables in the startDrag function would be using the current _width and_height properties to determine the boundaries.  If you couldn't understand that from my response, here is another attempt at writing it using some values... I don't know what your boundaries are, so assume tne normal boundaries are x = 100 to x = 300, and y = 100 to y = 400... and that the registreation point of the object is the upper left corner...

                         

                        // startDrag(target, lock, left, top, right, bottom)

                         

                        startDrag(this, false, 100, 100, 300-this._width, 400-this._height);

                         

                        That line of code should apply to any scale because it uses the current width/height, so you don't need different sets of code for each size

                        • 9. Re: Incrimental zoom buttons (CS4)
                          Gu55tav Level 1

                          Hi Ned,

                           

                          Sorry about that. Managed to get it to work.

                           

                          Thanks again!!!

                          • 10. Re: Incrimental zoom buttons (CS4)
                            Ned Murphy Adobe Community Professional & MVP

                            You're welcome