1 Reply Latest reply on Nov 13, 2006 6:47 AM by duckets

    animated button

    Level 7

      This may be a common question. If it is, I'd love to be pointed to where
      the answer may already exist.

      I want to create an effect where when you move over a sprite, it slides
      up the screen and when you move off it, it slides back down. I can
      create this effect by jumping to a new part of the Score where the
      animation is predefined. However, I'd like it to be more accurate. Say
      if you move the cursor off mid way through the animation, then I want it
      to animate in reverse from that point.

      So, has this type of effect been created as a sample behavior somwehre
      or does a tutorial exist? Or could you describe how it would be done? My
      Lingo is relatively beginner level.


        • 1. Re: animated button
          duckets Level 1


          Attached is a behaviour which does what you want.
          I've added comments to the code, which I hope describe how it works. There are 4 handlers. The beginsprite handler is called once, which director first encounters the sprite with the behaviour. In this handler, I store the original vertical location of the sprite. I also make a reference to the sprite in the variable 'my'.

          The enterFrame handler is called every frame. It has an 'if' statement which checks whether the variable 'mWithin' has been set to true or false, and makes the sprite rise or fall accordingly.

          The 'mouseEnter' and 'mouseLeave' handlers are automatically called by director when the mouse enters or leaves the sprite. In these, I set the 'mWithin' property to true or false.

          hope this is all clear!

          - Ben