8 Replies Latest reply on Sep 19, 2007 8:41 AM by rafa@mediatech

    Fade Effect

    rafa@mediatech Level 1
      I have a code on my buttons, which makes a blank image currently on stage get replaced with a different one when a button is rolled over.
      The code I am using is this:

      on mouseenter me

      sprite(3).member="a"


      on mouseleave me
      sprite(3).member="blank"

      end

      Very simple lingo. Is there a way that when the new image comes to view, it fades in when the mouse rolls over the button, instead of just popping in, and fade out once the mouse leaves the button, so that I end up with a smooth transition.

      Thank you.
        • 1. Re: Fade Effect
          Level 7
          Here's a simple behavior that you can attach to the sprite:

          property thisSprite
          property totalSteps
          property eachStep
          property animateMe

          on getPropertyDescriptionList
          myPropList = [:]
          myPropList.addProp(#totalSteps,[#comment:"select the number of steps
          for the fade:",#format:#integer,#range:[#min:5,#max:20],#default:10])
          return myPropList
          end

          on beginSprite me
          thisSprite = me.spriteNum
          animateMe = false
          eachStep = 100/totalSteps
          end

          on mouseEnter me
          animateMe = true
          end

          on mouseLeave me
          animateMe = false
          end

          on enterFrame me
          if animateMe then
          if sprite(thisSprite).blend > 0 then
          sprite(thisSprite).blend = sprite(thisSprite).blend - eachStep
          end if
          else
          if sprite(thisSprite).blend < 100 then
          sprite(thisSprite).blend = sprite(thisSprite).blend + eachStep
          end if
          end if
          end

          --
          Rob

          ___________
          Rob Dillon
          Adobe Community Expert
          http://www.ddg-designs.com
          412.243.9119
          • 2. Re: Fade Effect
            rafa@mediatech Level 1
            Im confused on what to do with:

            myPropList.addProp(#totalSteps,[#comment:"select the number of steps
            for the fade:",#format:#integer,#range:[#min:5,#max:20],#default:10])
            • 3. Re: Fade Effect
              Level 7
              You don't need to do anything with it. Just apply the behavior to your
              sprite, then a property window will open and ask you to select number of
              steps for the fade. That window is controlled by the
              getPropertyDescriptionList function.
              --
              Rob

              ___________
              Rob Dillon
              Adobe Community Expert
              http://www.ddg-designs.com
              412.243.9119
              • 4. Re: Fade Effect
                rafa@mediatech Level 1
                Ok. i get an error message when I compiled the code that reads:
                "String does not end correctly"
                myPropList.addProp9#totalSteps,[#comment:"select the number of steps?

                Anything specific I should put in the "?" space.
                • 5. Re: Fade Effect
                  Level 7
                  There' a carriage return in the text that you copied. You'll have to
                  remove the carriage return from the end of that line.
                  --
                  Rob

                  ___________
                  Rob Dillon
                  Adobe Community Expert
                  http://www.ddg-designs.com
                  412.243.9119
                  • 6. Re: Fade Effect
                    rafa@mediatech Level 1
                    The "return myPropList" line?
                    • 7. Re: Fade Effect
                      Level 7

                      > The "return myPropList" line?

                      nope, the line that gives the error (the one you pasted in your last
                      message).

                      It should start with:
                      myPropList.addProp

                      and end with:
                      #default:10])

                      On one single line.


                      --
                      ----------
                      Manno Bult
                      http://www.aloft.nl
                      • 8. Re: Fade Effect
                        rafa@mediatech Level 1
                        Guys:
                        Thanks for taking your time to help me with the issue.
                        I actually got an answer from another member that solved my problem. The code that was posted here was making the button sprite do the fade effect.
                        My friend did some tweaking to that code to achieve what I needed.
                        Here is the code:

                        property fadeSprite
                        property totalSteps
                        property eachStep
                        property animateMe


                        on getPropertyDescriptionList
                        myPropList = [:]
                        myPropList.addProp(#totalSteps,[#comment:"select the number of steps for the fade:",#format:#integer,#range:[#min:5,#max:20],#default:10])
                        myPropList.addProp(#fadeSprite,[#comment:"enter the sprite to fade:",#format:#integer,#default:1])
                        return myPropList
                        end


                        on beginSprite me
                        sprite(fadeSprite).blend = 0
                        animateMe = true
                        eachStep = 100/totalSteps
                        end


                        on mouseEnter me
                        animateMe = false
                        end


                        on mouseLeave me
                        animateMe = true
                        end


                        on enterFrame me
                        if animateMe then
                        if sprite(fadeSprite).blend > 0 then
                        sprite(fadeSprite).blend = sprite(fadeSprite).blend - eachStep
                        end if
                        else
                        if sprite(fadeSprite).blend < 100 then
                        sprite(fadeSprite).blend = sprite(fadeSprite).blend + eachStep
                        end if
                        end if
                        end


                        With this one, I am able to select which sprite is fading in and out. Again, thanks for your help.