1 Reply Latest reply on Feb 27, 2007 6:10 AM by Newsgroup_User

    Restore sprite

    Level 7
      I have 10 sprites and one button. Every time I push the button I want to
      change by random one sprite at a time. Then when I push the button again I
      need to restore the Sprite changed before.
      I have this code for the button:

      Button Code:

      On mouseUp me
      --I need to restore the sprite random before ???


      Please, can you tell me how to restore the sprite before?
      thank you very much.

        • 1. Re: Restore sprite
          Level 7
          You'll need to store the original member of the sprite, so that you know
          what member to go back to when you restore the sprite. You'll also need
          to store the number of the sprite that was changed, so that you can
          restore the correct sprite.

          You may also want to not change the sprite that has already been
          changed. In other words, you don't want to pick the same sprite number
          twice in a row.

          You can do all of this work from the button sprite. You can also do all
          of this on the mouseUp event.

          property spriteList
          property totalCount
          property currentChangedSprite
          property newMemberToUse
          property defaultMemberList

          on getPropertyDescriptionList
          myPropList = [:]
          myPropList.addProp(#spriteList,[#comment:"enter the sprite channnel
          numbers to be changed, separated by a
          myPropList.addProp(#newMemberToUse,[#comment:"pick the member to use
          on the change event:",#format:#member,#default:""])
          return myPropList

          on beginSprite me
          thisSprite = me.spriteNum
          -- make a list of the sprites from the numbers that were entered above...
          spriteList = stringToList(spriteList)
          totalCount = spriteList.count
          defaultMemberList = []
          -- build a list of the names of the default cast members used in the
          -- sprites in the sprite list...
          repeat with n = 1 to totalCount
          end repeat

          on mouseUp me
          if currentChangedSprite = VOID then -- no sprite has been changed
          currentChangedSprite = spriteList[random(totalCount)]
          sprite(currentChangedSprite).member = newMemberToUse
          -- find the original member for the sprite that was changed
          -- change this sprite to use the original member...
          thisOne = spriteList.getOne(currentChangedSprite)
          sprite(currentChangedSprite).member =
          -- find a new sprite to change...
          repeat with n = 1 to totalCount
          tempNumber = spriteList[random(totalCount)]
          if tempNumber <> currentChangedSprite then
          -- store the new value and change this sprite...
          currentChangedSprite = tempNumber
          sprite(currentChangedSprite).member = newMemberToUse
          exit repeat
          end if
          end repeat
          end if

          -- this function can be put in to a movie script window if you like
          on stringToList thisString
          oldDelim = the itemDelimiter
          the itemDelimiter = ","
          tempList = []
          thisManyItems = thisString.item.count
          repeat with n = 1 to thisManyItems
          end repeat
          the itemDelimiter = oldDelim
          return tempList

          I didn't try this, so you may find a typo. Watch for line wraps when you
          paste the code.

          Rob Dillon
          Adobe Community Expert