2 Replies Latest reply on Apr 1, 2012 8:05 PM by Natalie Butler

    Help with a basic timer behavior?

    Natalie Butler Level 1

      Okay, I'm sure several questions will be coming from me in the next couple weeks. I have some school projects due, and unfortunately I have very limited Director resources.


      Here is what I want to do:


      The sprite starts out as invisible.

      When the mouse clicks the sprite, a timer starts. The sprite moves to the location of the last mouse click and becomes visible.

      Once the timer is up and the timer's handler is called, the sprite becomes invisible again.


      There are multiple sprites on the stage that will be using this identical behavior.


      Here's what I have now, and I don't understand why it doesn't work. It makes sense in my head, but obviously not to Director! The only other behavior on these sprites is just a default Rotate Continuously (time-based).

      Thanks so much to anyone who can help!




      property spriteNum, alreadyClicked, my, myTimeout


      on beginSprite me

        alreadyClicked = 0

        my = sprite(spriteNum)

        my.visible = 0



      on mouseDown me

        if alreadyClicked = 0 then

          my.loc = _mouse.clickLoc

          alreadyClicked = 1

          my.visible = 1

          myTimeout = timeout().new(string(me), 15000, #timeUp, me)

        end if



      on timeUp me

        my.visible = 0


        alreadyClicked = 0


        • 1. Re: Help with a basic timer behavior?
          James Newton, ACP Level 3

          Hi Nathalie,


          When you set a sprite's .visible property to FALSE (or 0), it no longer reacts to mouse events. If you change...


            my.visible = 0

          ... to...

            my.blend = 0


          ... and ...


            my.visible = 1

          ... to...

            my.blend = 100


          ... then you might get the reactions that you are expecting from your sprite.


          However, currently, you have to click on the hidden sprite to make it appear.

          I am guessing that you want to be able to click anywhere on the stage in order to make the sprite appear at that location. Is that right? If so, that's going to need a somewhat different approach... but you can tell us about that next time.



          • 2. Re: Help with a basic timer behavior?
            Natalie Butler Level 1

            I knew it was a pretty simple fix. Blend instead of visible works! Thank you!