4 Replies Latest reply on Jul 13, 2006 6:49 AM by Newsgroup_User

    Grow a square shape

    Level 7
      Dear all:

      I want to open and then close smoothly (slide) litle by litle a square
      vector shape. This is the code I use, but does not work.

      repeat with h=1 to 200
      sprite(2).height=sprite(2).height + h
      end repeat

      Can you help me?

      Thank you



        • 1. Re: Grow a square shape
          Level 7
          > I want to open and then close smoothly (slide) litle by litle a square
          > vector shape. This is the code I use, but does not work.
          >
          > repeat with h=1 to 200
          > sprite(2).height=sprite(2).height + h
          > end repeat

          This won't work because it's all happening on one frame, so you'll never see
          anything happening. Instead, put something on the frame script so that it
          can refresh itself. Alternatively, you can add an "updateStage()" into that
          loop, but that can cause other problems, so it's probably better to loop on
          a frame instead.

          Also, the way you have it, the shape will increase in size by a greater
          amount each cycle. I'm guessing you don't want this. Replace the "h" in
          the height adjustment with a fixed value. Try 1 for starters, if that's too
          slow, adjust it to taste. (You can even use a non-integer if you want.)


          • 2. Re: Grow a square shape
            Level 7
            > I want to open and then close smoothly (slide) litle by litle a square
            > vector shape. This is the code I use, but does not work.

            By "doesn't work" do you mean "the appearance of the sprite doesn't
            change" or "it doesn't produce the effect I want, it does ... instead"?

            > repeat with h=1 to 200
            > sprite(2).height=sprite(2).height + h
            > end repeat

            You might try:
            repeat with h = 1 to 200
            sprite(2).height = sprite(2).height + 1
            updateStage
            end repeat

            but this will tend to lock out other animation (or make it run too fast
            depending on whether it's scripted).
            Perhaps instead something like this (attached to the sprite you want to
            "grow"):
            property spriteNum
            property my
            property _counter

            on beginSprite me
            my = sprite(spriteNum)
            _counter = 0
            end

            on exitFrame me
            if _counter < 200 then
            _counter = counter + 1
            my.height = my.height + 1
            end if
            end
            • 3. Re: Grow a square shape
              Level 7
              Thank you very much:
              I am using this code now, but is going very slow, how can I run quickly?

              on mouseUp me
              repeat with xx=1 to sprite(2).height
              sprite(2).locV = sprite(2).locV + 1
              updatestage
              end repeat
              end


              • 4. Re: Grow a square shape
                Level 7
                > on mouseUp me
                > repeat with xx=1 to sprite(2).height
                > sprite(2).locV = sprite(2).locV + 1
                > updatestage
                > end repeat
                > end

                What? This won't do what you want at all. You were closer the first time.
                All this will do is move the sprite, not grow it. Also, as I said, the
                updateStage trick is kind of a hack, and can cause other problems, like
                slowing down the playback, and preventing all other scripts from running.
                (It may also interrupt sound playback if you've got any audio going on.)

                Sean's approach will probably work the best. The only thing that's missing
                is that you should have a frame script that keeps the playhead looping on
                one frame until the grow is finished. On the frame, just have a script that
                says:

                on exitFrame
                go the frame
                end

                Then alter Sean's script like so:

                property spriteNum
                property my
                property _counter

                on beginSprite me
                my = sprite(spriteNum)
                _counter = 0
                end

                on exitFrame me
                if _counter < 200 then
                _counter = counter + 1
                my.height = my.height + 1
                else go the frame + 1
                end

                Only difference is I added the command to go to the next frame after the
                grow is completed. (You could also go to a marker or a specific frame or
                execute any other command at this point.)