6 Replies Latest reply on Nov 3, 2009 9:18 AM by rafa@mediatech

    Make a toggle button

    rafa@mediatech Level 1

      Hi Everyone,

      I have a button that allows the user to make the stage fullscreen and return it to normal screen. I was wondering how to make this into a toggle button so that it works all across the multiple pages of the project.

      in a movie script I have:

      on mCenterRectInRect r1, r2
        return rect(r2.width - r1.width, r2.height - r1.height, r2.width + r1.width, r2.height + r1.height)/2
      end

      then, the enlarge screen button has:

      on mouseUp me
        dr = (the desktopRectList)[1]
        sr = (the stage).sourceRect
       
        tWidthRatio  = float(dr.width )/sr.width
        tHeightRatio = float(dr.height)/sr.height
        ratio = min(tWidthRatio, tHeightRatio)
        tWidth  = sr.width  * ratio
        tHeight = sr.height * ratio
        tDrawRect = mCenterRectInRect(rect(0, 0, tWidth, tHeight), dr)
       
        (the stage).rect     = (the desktopRectList)[1]
        (the stage).drawRect = tDrawRect
        go to the frame +1
      end

      the "return to normal" button has:

      on mouseUp me
        (the stage).rect = rect(295, 288, 935, 786)
        (the stage).drawRect = rect(0, 0, 644, 503)  
        go to the frame -1
      end

       

      I have used this code in single page projects... but now I need to incorporate it to a multiple page project...

       

      thank you in advance!

      Rafa.

        • 1. Re: Make a toggle button
          robdillon Most Valuable Participant

          To combine the two functions to be used with one button, you can just add a boolean variable to act as the toggle but... you have a lot going on in the functions that could, and should, be relegated to a beginSprite function. You only need to know the size of the user's screen once, for instance.

           

          So, how about something like this:

           

          ----------------------------

          property thisSprite -- the button sprite

          property makeFullScreen - the boolean to act as the switch

          property dr
          property sr
          property  tWidthRatio
          property  tHeightRatio
          property ratio
          property  tWidth
          property  tHeight

           

          on beginSprite me

               makeFullScreen = false

               dr = (the desktopRectList)[1]
                sr = (the stage).sourceRect
                tWidthRatio  = float(dr.width )/sr.width
                tHeightRatio = float(dr.height)/sr.height
                ratio = min(tWidthRatio, tHeightRatio)
                tWidth  = sr.width  * ratio
                tHeight = sr.height * ratio

          end


          on mouseUp me

               makeFullScreen = not makeFullScreen

               if makeFullScreen then

                    tDrawRect = mCenterRectInRect(rect(0, 0, tWidth, tHeight), dr)
                    (the stage).rect     = (the desktopRectList)[1]
                   (the stage).drawRect = tDrawRect
                   --go to the frame +1

              else
                 (the stage).rect = rect(295, 288, 935, 786)
                 (the stage).drawRect = rect(0, 0, 644, 503)  
                 --go to the frame -1

              end if

          end

          ----------------------------------

           

          I commented out your move forward and back by one frame. I have no idea if they will be needed if you combine this code. To make this button work across the entire movie, just extend the sprite to the end of the score.

          1 person found this helpful
          • 2. Re: Make a toggle button
            rafa@mediatech Level 1

            Rob,

            Thank you so much for your help. This is working great. One concern... when the video returns to standard size it is not returning to 800x600 (this is the default size of the project). I thought it had to da with the line that reads:

             

            else
                (the stage).rect = rect(295, 288, 935, 786)
                (the stage).drawRect = rect(0, 0, 644, 503)

            end if

             

            I changed:

            (the stage).drawRect = rect(0, 0, 644, 503)

             

            to:

            (the stage).drawRect = rect(0, 0, 800, 600)

             

            ...but when the user clicks to return to normal, the stage it wasy off the frame of the 800x600 window. Do you know what might be causing this?

             

            thank you,

            Rafa.

            • 3. Re: Make a toggle button
              robdillon Most Valuable Participant

              The rect property is the position of the stage on the user's computer screen. The drawRect is the size of the stage in that window space. Ideally they should be the same dimensions, but probably not the same values. In your code the rect is 640 X 498 and the first drawRect is 644 X 503 and the second is 800 X 600. The first is closer. Try using 640 X 498, or whatever the original size of the stage was.

              1 person found this helpful
              • 4. Re: Make a toggle button
                rafa@mediatech Level 1

                Rob,

                That still shows the stage offscreen (and screen not 800x600). I went to the "message window" and typed:

                put (the stage).drawRect

                 

                It returned:

                rect(57, 40, 857, 640)

                 

                When published this way the project still shows offscreen and window is not 800x600 (after toggled back to normal screen). I inserted the dimensions you suggested:

                (the stage).drawRect = rect(57, 40, 640, 498)

                 

                ... but now the stage is more centered (not completely) and stage is still smaller than 800x600 (after toggled back to normal screen). How can I get my project's original window size and stage position and tell it to return to this specifically?

                 

                thank you,

                Rafa.

                • 5. Re: Make a toggle button
                  rafa@mediatech Level 1

                  Got it!

                  I created two new properties:

                  property origSize
                  property origPos

                   

                  defined them on:

                   

                  on beginSprite me

                    makeFullScreen = false
                   
                    dr = (the desktopRectList)[1]
                    sr = (the stage).sourceRect
                    tWidthRatio  = float(dr.width )/sr.width
                    tHeightRatio = float(dr.height)/sr.height
                    ratio = min(tWidthRatio, tHeightRatio)
                    tWidth  = sr.width  * ratio
                    tHeight = sr.height * ratio
                    origSize = (the stage).rect
                    origPos = (the stage).drawRect

                  end

                   

                  ...and use them on the else if:

                  else
                      (the stage).rect = origSize
                      (the stage).drawRect = origPos

                  end if

                   

                  this seems to be working porperly!

                  Thanl you Rob!

                   

                  Rafa.

                  • 6. Re: Make a toggle button
                    rafa@mediatech Level 1

                    Thank you for your help Rob.

                     

                    Rafa.