2 Replies Latest reply on Feb 23, 2011 8:52 AM by Handycam

    Zoom scroller "to fit"?

    Handycam Level 1

      I have a group component in a scroller.  My application will add children to this component.  The component's scale is set with a Spark HSlider.  Fine.

       

      However, I'd like to provide a "zoom to fit" button.  I can get the size in pixels of all the children added, no problem. My question is how I can use this dimension to properly set the scaleX and scaleY so it fits in the viewport.

       

      <s:Group id="clipWindow" width="720" height="480">
           <s:Scroller id="imgScroll" top="0" left="0" bottom="0" right="0">
                <s:Group id="bgimg" scaleX="{scaleSlider.value}" scaleY="{scaleSlider.value}">
                     <com:WorkshopStage id="ws" />
                </s:Group>
           </s:Scroller>
      </s:Group>
      

        • 1. Re: Zoom scroller "to fit"?
          MikisMM Level 2

          Basicly this is only math stuff. Here is what you will have to write inside your "Zoom To Fit" handler:

           

          bgimg.scaleX = bgimg.scaleY = Math.min(clipWindow.width  / ws.width,
                                                 clipWindow.height / ws.height,
                                                 1);
          

          Now this formula only scales down your bgimg if it (actually I use dimensions of ws but that does not matter here) is larger than the clipWindow. If it is smaller, scale will be 1: it won't scale up.

          And as you can see there is no need for calculating the size of ws manually by somehow checking all children: flex does that for you when components are measured.

           

          Michael

          • 2. Re: Zoom scroller "to fit"?
            Handycam Level 1

            Thanks I figured it was math, but it was never my strongest suit!