4 Replies Latest reply on Jan 13, 2010 5:03 AM by James Newton, ACP

    Buttons and Sprites

    Stuart Gloucester

      Hi - I want to create a button in Director that will remove a sprite from the stage. I also want this same button to return the sprite to the stage when I click on it again. I have looked in the Lib palette and behaviours and can see anything suitable. Can this be done with some script?





        • 1. Re: Buttons and Sprites
          Chunick Level 3

          Yes, it can be done.


          You don't mention which version of Director you are using, but I'll assume DMX2004 or higher. Try out the makeScriptedSprite() and removeScriptedSprite() methods, or you can simply move the sprite off and on stage by changing it's .loc property.

          • 2. Re: Buttons and Sprites
            Stuart Gloucester Level 1

            Hi Joshua


            I am using version 8.5


            Just tried what what said, and a script error is returned for removeScripted


            Any ideas??


            The change location wont work as I want to be able to click on one button and remove something else.



            • 3. Re: Buttons and Sprites
              Mike Blaustein Level 4

              the scriptedSprite stuff did not exist in version 8.5.  Back then you would use puppetSprite to create a "temporary" sprite on the stage, and to remove it.  But I think that you are trying to take the hard way by actually creating and destroying the sprite.  As Josh mentioned, it is much easier to simply move the sprite off the stage when you want it gone. Then the user can't see it, so it appears to have been destroyed.  You can also change the blend of the sprite to 0, or set the visible of the channel to false in order to hide a sprite.  It all depends upon what you need to do specifically.

              • 4. Re: Buttons and Sprites
                James Newton, ACP Level 3

                Here's a behavior that you can attach to the sprite that you wish to remove from the stage:


                -- SHOW AND HIDE --

                -- Behavior



                -- Attach this behavior to a graphic sprite.


                -- 091229 JN: ShowHide_Toggle() now only sets the rect of the sprite

                --            the rect is to change.


                -- PROPERTY DECLARATIONS --

                property hideOnBeginSprite  -- if TRUE, then sprite is moved offstage

                property pSprite            -- pointer to this sprite

                property pOnRect            -- initial (on-stage) rect of this sprite

                property pOffRect           -- rect which places this sprite off-stage

                -- SPRITE EVENTS --

                on beginSprite(me) ---------------------------------------------------

                  -- ACTION: Initializes properties



                  pSprite = sprite(me.spriteNum)

                  pOnRect = pSprite.rect

                  pOffRect = pOnRect.offset(-pOnRect.right, 0)


                  if hideOnBeginSprite then


                  end if

                end beginSprite

                -- PUBLIC METHOD --

                on ShowHide_Toggle(me, aShow) ----------------------------------------

                  -- INPUT: <aShow> is considered TRUE if it is VOID or 1, FALSE for

                  --         any other value

                  -- ACTION: ShowHide_Toggle() and ShowHide_Toggle(1) will replace

                  --         this sprite in its starting position. ShowHide_Toggle(0),

                  --         ShowHide_Toggle(#hide) or any other value will move it

                  --         off-stage.



                  if voidP(aShow) or (aShow = TRUE) then

                    vRect = pOnRect



                    vRect = pOffRect

                  end if


                  if pSprite.rect <> vRect then

                    pSprite.rect = vRect

                  end if

                end ShowHide_Toggle

                -- BEHAVIOR PARAMETERS --

                on getPropertyDescriptionList(me)

                  vPropertyList = [:]


                  vPropertyList[ \

                #hideOnBeginSprite] = [ \

                #comment: "Hide on beginSprite", \

                #format:   #boolean, \

                #default:  FALSE]


                  return vPropertyList

                end getPropertyDescriptionList


                From your button, you can use sendSprite(<spriteNum>, #ShowHide_Toggle, <TRUE or FALSE>)