2 Replies Latest reply on Jan 31, 2007 10:13 AM by Newsgroup_User

    Sprite gets stuck in mid-movement

    quadpolar Level 1
      I am having some trouble with a sprite not knowing when the mouse is outside it's bounding edges, and when it's inside.

      I have a script set up, so that when you roll over the particular sprite, it moves to the left 40 pixels, 10 pixels at a time so it has a smooth effect.

      when you roll off of the sprite, the sprite should move back to the right 40 pixels, but once again it moves 10 pixels at a time. Somewhere in my script, the sprite gets stuck. if you roll over the sprite too quickly the sprite stops after moving 10 pixels, and then won't move again. At all. It's stuck. I know someone out there knows why this isn't working. Any help is much appreciated. Thanks so much.

      -So here's my script.

      property pRight
      property pLeft

      on beginSprite me
      pRight=0 --set it to not shrink when it starts up
      pLeft=0
      end

      on mouseEnter me
      pLeft = 1
      end


      on mouseLeave me
      pRight=1 --start shrinking now
      end


      on enterFrame me
      if pRight=1 then
      if sprite("Button 1").locH<470 then
      sprite("Button 1").locH=sprite("Button 1").locH+10
      else
      pRight=0 --now it will stop shrinking
      end if
      end if
      if pLeft = 1 then
      if sprite("Button 1").locH>440 then
      sprite("Button 1").locH=sprite("Button 1").locH-10
      else pLeft = 0
      end if
      end if



      end
        • 1. Re: Sprite gets stuck in mid-movement
          BSpero Level 1
          There is probably a better way to write this up, but using your code, the problem is that it is possible to end up with both of the properties set to "1". Then, on the enterFrame, they just cancel each other out. So, on mouseEnter, set the pRight to 0 at the same time you set the pLeft to 1. Do the same for the mouseLeave...

          on mouseEnter me
          pLeft = 1
          pRight = 0 -- make sure that you are not trying to move it both ways
          end


          on mouseLeave me
          pRight=1 --start shrinking now
          pLeft = 0 -- make sure that you are not trying to move it both ways
          end

          • 2. Re: Sprite gets stuck in mid-movement
            Level 7
            Yes, or instead of using two parameters just use one, maybe called
            pDirection and set it to 1 or -1 then in your enterFrame, don't use two
            different if statements. It will work but it's not efficient.

            if pDirection = 1 then


            else
            if pDirection = -1 then

            end if
            end if

            This shows anyone reading your code that the value of pDirection can only be
            one or the other, even though in your code it doesn't matter because the
            value of your parameter cannot change inside a handler unless you set it
            yourself.


            --
            Craig Wollman
            Lingo Specialist
            Word of Mouth Productions
            212-928-9581

            www.wordofmouthpros.com
            "BSpero" <webforumsuser@macromedia.com> wrote in message
            news:epqjgr$f7o$1@forums.macromedia.com...
            > There is probably a better way to write this up, but using your code, the
            > problem is that it is possible to end up with both of the properties set
            > to
            > "1". Then, on the enterFrame, they just cancel each other out. So, on
            > mouseEnter, set the pRight to 0 at the same time you set the pLeft to 1.
            > Do the
            > same for the mouseLeave...
            >
            > on mouseEnter me
            > pLeft = 1
            > pRight = 0 -- make sure that you are not trying to move it both ways
            > end
            >
            >
            > on mouseLeave me
            > pRight=1 --start shrinking now
            > pLeft = 0 -- make sure that you are not trying to move it both ways
            > end
            >
            >
            >