6 Replies Latest reply on Dec 30, 2010 8:38 AM by Production Monkey

    Get Sprite Number for Named Member

    schneb

      This seems like it would be real simple, but it has me stumped.

       

      I have a checkbox castmember named "Itemize" that is on channel 7 of my score. I am not sure if it will stay on channel 7, so I want to be able to read its "state" without using the channel number. The following will tell me the checked state...

       

      put sprite(7).selected

       

      Since I do not want to use the channel number, how can I identify the sprite using its name? I tried this without positive results...

       

      put member("Itemize").sprite

       

      You would think that or something similar would work--but it doesn't. Anyone have a magic bullet?

       

      Thanks in advance!

        • 1. Re: Get Sprite Number for Named Member
          Mike Blaustein Level 4

          It looks like you are using a flashComponent for your checkbox.  Those are not controllable by the member... only the sprite.  You can name the sprite, so your references are not numeric...  When you click on the sprite, at the top of the Property Inspector (sprite tab), there is a Name field.  Enter a name there and you can refer to the sprite like:

           

          put sprite("nameYouChose").selected

          • 2. Re: Get Sprite Number for Named Member
            schneb Level 1

            That worked just fine for me, Mike. Thanks alot!

            • 3. Re: Get Sprite Number for Named Member
              Super_Noodles Level 1

              I need to do something similar and though this was the best thread for it.

               

              I have multiple sprites displayed and need to carry out the same task on all off them, depending on which one is 'selected'

               

              When a sprite is clicked I need to do these:

               

              1 -> 'Deselect' all other sprites.

                        -> Change the style of them like this: (I think can only be done individually)

                               sprite("Sprite1").color=RGB(0,0,0)

                               sprite("Sprite1").lineSize=1

                               sprite("Sprite2").color=RGB(0,0,0)

                               sprite("Sprite2").lineSize=1

                        -> Clear the contents of a list.

               

              2. -> Change the style of only the selected sprite and add items to the list.

               

              Is there a way to do something like this (I know this returns an error but I can't find how to do it):

               

              put member(this).sprite

               

              Does anyone have a solution as I'd really prefer to have as few lines as possible to keep things tidier and simpler in my Lingo.

               

              Thanks

              • 4. Re: Get Sprite Number for Named Member
                Super_Noodles Level 1

                Worked out how to change labels. Pretty simple really

                 

                     sprite("llist_name").labels = ["1st Item","2nd Item"]

                     sprite("list_name").data = ["1st Item","2nd Item"]

                • 5. Re: Get Sprite Number for Named Member
                  ptemedia1 Level 1

                  Try this at the top of the code:

                   

                   

                  property spriteNum

                  property pMemberName

                   

                  on beginSprite me

                    pMemberName = sprite(spriteNum).member.name

                  end

                   

                   

                  -- then make all the sprites 'inactive' as you say. I'm not sure if you can do them all in 1 line

                   

                  on mouseDown

                   

                  sprite("Sprite1").color=RGB(0,0,0)

                  sprite("Sprite1").lineSize=1

                   

                  sprite("Sprite2").color=RGB(0,0,0)

                  sprite("Sprite2").lineSize=1

                   

                   

                   

                    sprite(pMemberName).color = RGB(255,0,0) -- This will now be red

                    sprite(pMemberName).lineSize = 2 -- and the line will be thicker

                   

                  --you can then use if and else if to have unique code run depending on which sprite is selected

                   

                    if pMemberName = "Sprite1" then

                       --it will do the code her

                    else if pMemberName = "Sprite1" then

                   

                       --it will do code her

                  end if

                   

                  end

                   

                  Hope all that helps

                   

                  You say you've got your list working to change values? Do you know how to set a default value? Thanks

                  • 6. Re: Get Sprite Number for Named Member
                    Production Monkey Level 3

                    Using "sendAllSprites" and a behavior is the proper way to do what you want. Paste the code below into a behavior script and attach it to all the sprites that are part of your group of sprites.

                     

                    --  Group Highlight Behavior

                     

                    property  pSprite
                    property  pMyGroupName
                    property  pSelectColor
                    property  pSelectLineSize
                    property  pDeSelectColor
                    property  pDeSelectLineSize

                     


                    On GetBehaviorDescription me
                      return "Group Highlight Behavior. "
                    end GetBehaviorDescription

                     

                     

                     

                    On GetPropertyDescriptionList me
                      Props = [:]
                      Props[#pMyGroupName] = [#default:"Group01", #format:#String,  #comment:"Group  Name"]
                      Props[#pSelectColor] = [#default:rgb(255,0,0), #format:#Color, #comment:"Select color"]
                      Props[#pSelectLineSize] = [#default:2, #format:#integer, #Range:[#min:1, #max:10], #comment:"Select line size"]
                      Props[#pDeSelectColor] = [#default:rgb(0,0,0), #format:#Color, #comment:"Unselect color"]
                      Props[#pDeSelectLineSize] = [#default:1, #format:#integer, #Range:[#min:1, #max:10], #comment:"Unselect line size"]
                      return Props
                    end GetPropertyDescriptionList

                     


                    on beginSprite me
                      pSprite = sprite(me.spriteNum)
                      -- setup default values
                    end beginSprite

                     


                    on mouseDown me
                      sendAllSprites(#deselect, pMyGroupName)  -- 'Deselect' all other sprites with  the same "Group Name".
                      me.select()  -- Change the style of this sprite to selected.
                    end mouseDown

                     


                    on deselect me, GroupName
                      if GroupName = pMyGroupName then  -- make sure this sprite is part of the group
                        pSprite.color = pDeSelectColor
                        pSprite.lineSize = pDeSelectLineSize
                      end if
                    end deselect

                     


                    on select me
                      pSprite.color = pSelectColor
                      pSprite.lineSize = pSelectLineSize
                    end deselect