7 Replies Latest reply on Jun 21, 2006 5:37 PM by christian_cruz

    Value to multiple sprites through the same parameter

    christian_cruz
      I'm going to ask the same question " "contains" doubt in hexadecimal color value?" but in a different way, because I figured out that the solution is simpler that I thought, and the solutions goes by other way. I have this behavior:

      property pTargetSprite, pBlendValue

      on getPropertyDescriptionList me
      list = [:]

      addProp list, #pTargetSprite, [#comment: "Target Sprite:",\
      #format: #integer, #default: VOID]

      addProp list, #pBlendValue, [#comment: "Blend Value:",\
      #format: #integer, #default: 100]

      return list

      end


      on mouseDown me

      sprite(pTargetSprite).blend = pBlendValue

      end

      I would like to enter MULTIPLE sprites for 1 parameter, that is to say when the dialog box of the behavior appears and ask me the "Target Sprite:", I would like to input ...let's say 1 , 2 , 3 , ... whatever numbers I want. Therefore, the blend values of that sprites will change according to the input Blend Value. Right Now is working perfect, but of course with only ONE sprite, but I want to be able to assign that Blend Value to multiple sprites over the same parameter.

      I guess it must be very simple, but I cannot get the answer anywhere in my brain, nor my director book, nor in the forums.

      Thanks!!!

        • 1. Re: Value to multiple sprites through the same parameter
          a¿ex Level 1
          maybe I didn't understand your question, but it seems as you could simply select all sprites, which you want to affect in the score and enter the value for the gpdl property in the Property Inspector -> Behavior tab.
          • 2. Re: Value to multiple sprites through the same parameter
            Level 7
            Instead of using an integer for your pTargetSprite property, you can use
            a list. Make sure that you enter the list correctly. It should be a
            series of integers, separated by commas, surrounded by square brackets-
            like this [1,2,3,4]. If you want just one sprite to be blended, then
            just put it in brackets like [2]. You can also use sprite names if you
            name your sprites and are using Director MX 2004, in that case you would
            use a series of strings, like ["someSpriteName","someOtherSprite"]



            property pTargetSprite, pBlendValue

            on getPropertyDescriptionList me
            list = [:]

            addProp list, #pTargetSprite, [#comment: "Target Sprites:",\
            #format: #list, #default: [1,2]]

            addProp list, #pBlendValue, [#comment: "Blend Value:",\
            #format: #integer, #default: 100]

            return list

            end


            on mouseDown me
            repeat with i=1 to pTargetSprite.count
            sprite(pTargetSprite ).blend = pBlendValue
            end repeat
            end
            • 3. Re: Value to multiple sprites through the same parameter
              Level 7
              You have several options here. You can do as you suggest, create a list
              of the sprite numbers to change and then tell each of those sprite's
              blend value to change.

              Another method is to write a function in the behavior that you attach to
              each sprite and then use sendAllSprites() to fire each of those
              functions. If you are attaching behaviors to each sprite this may be the
              way to go.

              For method 1, you could amend your behavior like this:

              ----------
              property spriteList
              property blendValue

              on getPropertyDescriptionlist
              myPropList = [:]
              myPropList.addProp(#spriteList,[#comment:"enter the sprite channel
              numbers to use, separated by commas:",#format:#integer,#default:"1,2,3"])
              myPropList.addProp(#blendValue, [#comment: "Blend Value:",\
              #format: #integer, #default: 100])
              return myPropList
              end

              on beginSprite me
              spriteList = stringToList(spriteList)
              end

              on stringToList(thisString)
              oldDelim = the itemDelimiter
              the itemDelimiter = ","
              thisManyItems = thisString.item.count
              tempList = []
              repeat with n = 1 to thisManyItems
              tempList.add(thisString.item[n])
              end repeat
              the itemDelimiter = oldDelim
              return tempList
              end

              on mouseUp me
              thisMany = spriteList.count
              repeat with n = 1 to thisMany
              sprite(n).blend = blendValue
              end repeat
              end
              ---------

              for method 2 you could use something like this in each sprite's behavior:


              ------------
              property blendValue
              property thisSprite

              on getPropertyDescriptionlist
              myPropList = [:]
              myPropList.addProp(#blendValue, [#comment: "Blend Value:",\
              #format: #integer, #default: 100])
              return myPropList
              end

              on beginSprite me
              thisSprite = me.spriteNum
              end

              on changeValue me
              sprite(thisSprite).blend = blendValue
              end
              ----------

              and then you can call this second method from a mouse event:

              on mouseUp me
              sendAllSprites(#changeValue)
              end

              and every sprite that contains that function in the frame where it is
              called will execute.

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

              http://www.macromedia.com/software/trial/
              • 4. Value to multiple sprites through the same parameter
                christian_cruz Level 1
                Thanks a lot, it's almost working, with a minor tweak (*) it is almost done. BUT!!! something strange happens.
                By the way I prefer method 1.

                quote:



                property spriteList
                property blendValue

                on getPropertyDescriptionlist
                myPropList = [:]
                myPropList.addProp(#spriteList,[#comment:"enter the sprite channel \
                numbers to use, separated by commas:",#format:#integer,#default:"1,2,3"]) -- <<< (*)

                -- (The INTEGER must be a STRING, otherwise it does not work)

                myPropList.addProp(#blendValue, [#comment: "Blend Value:",\
                #format: #integer, #default: 100])
                return myPropList
                end

                on beginSprite me
                spriteList = stringToList(spriteList)
                end

                on stringToList(thisString)
                oldDelim = the itemDelimiter
                the itemDelimiter = ","
                thisManyItems = thisString.item.count
                tempList = []
                repeat with n = 1 to thisManyItems
                tempList.add(thisString.item[n])
                end repeat
                the itemDelimiter = oldDelim
                return tempList
                end

                on mouseUp me
                thisMany = spriteList.count
                repeat with n = 1 to thisMany
                sprite(n).blend = blendValue
                end repeat
                end




                No matter what sprites I enter the behavior always start from sprite 1, and no matter what sprite number, the behavior works SEQUENTIALLY. That is to say, If I enter sprites 5, 11, 67, 150, the behavior instead of changing those sprites, it counts from 1 and change IN ORDER sprites 1,2,3,4 because that was the total amount of sprites entered. The Blend is working perfect. BUT!! I tried several things, but it always start from 1 and in order.

                Please!!!!! Help!!!!!!!
                • 5. Re: Value to multiple sprites through the same parameter
                  Level 7
                  Hi Christian,

                  My mistake, the mouseUp function should look like this:

                  on mouseUp me
                  thisMany = spriteList.count
                  repeat with n = 1 to thisMany
                  sprite(spriteList[n]).blend = blendValue
                  end repeat
                  end


                  As it was, the function was just putting the current value of n into the
                  sprite number. You really want item n in the list. This should fix that.

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

                  http://www.macromedia.com/software/trial/
                  • 6. Re: Value to multiple sprites through the same parameter
                    Level 7
                    In the mouseUp handler, change the line:

                    sprite(n).blend = blendValue
                    to:
                    sprite(value(spriteList[n])).blend = blendValue






                    • 7. Re: Value to multiple sprites through the same parameter
                      christian_cruz Level 1
                      Rob, Anders... THANKS A LOT!!! Now it works perfect.

                      property spriteList
                      property blendValue

                      on getPropertyDescriptionlist
                      myPropList = [:]
                      myPropList.addProp(#spriteList,[#comment:"enter the sprite channel \
                      numbers to use, separated by commas:",#format:#string,#default:"1,2,3"]) -- <<< (*)
                      myPropList.addProp(#blendValue, [#comment: "Blend Value:",\
                      #format: #integer, #default: 100])
                      return myPropList
                      end

                      on beginSprite me
                      spriteList = stringToList(spriteList)
                      end

                      on stringToList(thisString)
                      oldDelim = the itemDelimiter
                      the itemDelimiter = ","
                      thisManyItems = thisString.item.count
                      tempList = []
                      repeat with n = 1 to thisManyItems
                      tempList.add(thisString.item[n])
                      end repeat
                      the itemDelimiter = oldDelim
                      return tempList
                      end

                      on mouseUp me
                      thisMany = spriteList.count
                      repeat with n = 1 to thisMany
                      sprite(value(spriteList[n])).blend = blendValue
                      end repeat
                      end