9 Replies Latest reply on May 24, 2008 10:43 PM by Newsgroup_User

    Zoom In/Out Auto

    Renos83 Level 1
      I'm doing a project in Macromedia Director MX 2004 (windows xp). The project includes a gallery.

      I would like to know how you can have a zoom in auto effect when you rollover the mouse pointer on a thumbnail of the gallery and a zoom out effect when you leave the thumbnail area (something like the Bar Menu on Mac OS). Please! Any help would be useful!

      Thanks
        • 1. Re: Zoom In/Out Auto
          Level 7
          If I understand you right, you just have to play the the rect of the
          object your mouse is over. Just put something like this in each item
          you're mouse goes over that you want to change the size of.

          -------------------------------------------------------------
          global a,b,c,d

          on mouseEnter me
          cursor 280
          a = sprite(the currentSpriteNum).left
          b = sprite(the currentSpriteNum).top
          c = sprite(the currentSpriteNum).right
          d = sprite(the currentSpriteNum).bottom
          sprite(the currentSpriteNum).rect = rect(a-2,b-2,c+2,d+2)
          end

          on mouseLeave me
          cursor -1
          sprite(the currentSpriteNum).rect = rect(a,b,c,d)
          end

          on mouseWithin me
          cursor 280
          end

          on mouseDown me
          sprite(the currentSpriteNum).rect = rect(a,b,c,d)
          end

          on mouseUp me
          cursor -1
          sprite(the currentSpriteNum).rect = rect(a-2,b-2,c+2,d+2)
          go to frame "WhateverFrameYouWant"
          end
          -------------------------------------------------------------

          Hope that helps.
          • 2. Re: Zoom In/Out Auto
            Renos83 Level 1
            Thank you very much for the answer. I just wanted to know, can you have an effect like this more "animated" (meaning something like different sizes per frame, so it gives you a "like video" zoom in/out effect). Hope you understand what I'm saying! Excuse my English! :)
            • 3. Re: Zoom In/Out Auto
              Level 7
              I'm not sure I understand what you're looking for, but you could do the
              calculations inside a mouseWithin handler instead of the mouseEnter
              handler and have the size of the image step up with each frame until it
              reaches a maximum value you set. Something like:

              if i < 5
              sprite(the currentSpriteNum).rect = rect(a-1,b-1,c+1,d+1)
              i = i + 1
              end

              You'd have to dink around with it to get exactly what you're looking for.
              • 4. Re: Zoom In/Out Auto
                Renos83 Level 1
                When the mouse is in the area of the image, the image zooms in without stopping. When the mouse leaves the area it returns to its regular size on stage screen. This is the Lingo I used :

                global a,b,c,d

                on mouseWithin me
                cursor 280
                a = sprite(the currentSpriteNum).left
                b = sprite(the currentSpriteNum).top
                c = sprite(the currentSpriteNum).right
                d = sprite(the currentSpriteNum).bottom
                sprite(the currentSpriteNum).rect = rect(a-1,b-1,c+1,d+1)
                end

                on mouseLeave me
                cursor -1
                a = 323
                b = 152
                c = 511
                d = 393
                sprite(the currentSpriteNum).rect = rect(a,b,c,d)
                end

                My question is how do I use the "if_then" command like you told me on your last reply ,so the image on mouseWithin would stop, for example in
                a value like rect(a-10,b-10,c+10,d+10).

                • 5. Re: Zoom In/Out Auto
                  Level 7
                  That is a terrible way to do your zoom effect. For several reasons.
                  Using globals for the a,b,c, and d values is overkill. Unless other
                  sprites need access to those values, it is better to use properties, and
                  in fact, you can use a single property to store the entire rect. Also,
                  you don't need to hard code the values. The way I did it will store the
                  original rect that you set in authoring mode, so you can use the same
                  behaviour without any changes on multiple sprites. Also, doing your
                  scaling on mouseWithin is not a good idea for several reasons. First
                  off, it is difficult to make it zoom back out since there is no
                  opposite, like mouseNotWithin. Second, it messes up some time based
                  animations, so using enterFrame like I did here is a better method.

                  Basically, there is a property called pGrowing which is set to 0 at
                  first. When it is 0, nothing happens. On enterFrame, it gets set to 1.
                  As long as pGrowning is 1, then it will start to scale upwards, until
                  it is 10 pixels larger in each direction, then pGrowing gets set back to
                  0 so it stops growing.

                  And on mouseLeave, it gets set to -1 which means start shrinking. And
                  the same process happens in reverse.

                  Watch for inadvertent line breaks... this should be exactly 35 lines of
                  code.

                  ----

                  property pGrowing, pRect

                  on beginSprite me
                  pRect=sprite(me.spriteNum).rect
                  pGrowing=0
                  end

                  on mouseEnter me
                  cursor 280
                  pGrowing=1

                  end

                  on mouseLeave me
                  cursor -1
                  pGrowing=-1
                  end

                  on enterFrame me
                  case pGrowing of
                  1: --growing
                  if sprite(me.spriteNum).rect[1] = pRect[1]-10 then
                  pGrowing=0
                  else
                  sprite(me.spriteNum).rect =
                  sprite(me.spriteNum).rect+rect(-1,-1,1,1)
                  end if

                  -1: --shrinking
                  if sprite(me.spriteNum).rect[1] = pRect[1] then
                  pGrowing=0
                  else
                  sprite(me.spriteNum).rect =
                  sprite(me.spriteNum).rect-rect(-1,-1,1,1)
                  end if
                  end case
                  end
                  • 6. Re: Zoom In/Out Auto
                    Renos83 Level 1
                    Thank you very much for your information and support!

                    But when I Copy/Paste the code you just gave me in the script of the image it says

                    "Script error: Operand expected

                    sprite(me.SpriteNum).rect = ?

                    • 7. Re: Zoom In/Out Auto
                      Renos83 Level 1
                      Ok! Got It! Thank you very much. I just had to write the equation in the same line.Thanks!
                      • 8. Re: Zoom In/Out Auto
                        Level 7
                        you have to put sprite(me.spriteNum).rect+rect(-1,-1,1,1) in the same line..
                        example:

                        sprite(me.spriteNum).rect = sprite(me.spriteNum).rect+rect(-1,-1,1,1)

                        hth

                        • 9. Re: Zoom In/Out Auto
                          Level 7
                          Cool, Mike. I knew there had to be a better way. I wrote that code a
                          few years ago and just haven't bothered to update it with things I've
                          learned since then.