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

    Restore sprite

    Level 7
      Hello:
      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 ???

      ----
      Rnd=random(10)
      Sp=Sprite(Rnd).member
      Sprite(Rnd).member=member("c"&Rnd&"On")
      updatestage
      End

      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
          comma",#format:#string,#default:""])
          myPropList.addProp(#newMemberToUse,[#comment:"pick the member to use
          on the change event:",#format:#member,#default:""])
          return myPropList
          end

          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
          defaultMemberList.add(sprite(spriteList[n]).member.name)
          end repeat
          end

          on mouseUp me
          if currentChangedSprite = VOID then -- no sprite has been changed
          yet...
          currentChangedSprite = spriteList[random(totalCount)]
          sprite(currentChangedSprite).member = newMemberToUse
          exit
          else
          -- 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 =
          member(defaultMemberList[thisOne])
          -- 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
          end


          -- 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
          tempList.add(value(thisString.item[n]))
          end repeat
          the itemDelimiter = oldDelim
          return tempList
          end
          ----------------

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

          --
          Rob
          _______
          Rob Dillon
          Adobe Community Expert
          http://www.ddg-designs.com
          412-243-9119

          http://www.macromedia.com/software/trial/