7 Replies Latest reply on Jan 2, 2007 6:09 PM by Lukewig

    Radio button code

    Level 7
      hi everyone
      I got the following code(for radio buttons) from some where and trying to
      make it work.
      The part I dont understand is the whoIsSelected handler I dunno how its
      activated.
      If anyone could explain, please do.

      thanx
      ahmed

      *******************
      property myGroupID

      property myGroupList

      property myState

      on beginsprite me


      -- make sure the hilite is correctly set

      sprite(me.spriteNum).member.hilite = myState


      -- now collect other members of the group

      sendAllSprites(#CollectRadioGroup, [], myGroupID)


      -- if this button is selected, make sure the others are not

      if myState then call(#GroupSelect, myGroupList, me)


      end

      on endSprite (me)


      -- Delete the reference to this object from the groupList

      myGroupList.deleteOne(me)


      end

      on CollectRadioGroup (me, groupList, groupID)


      -- Create a references to the groupList, and add self to it

      if myGroupID = groupID then

      myGroupList = groupList

      myGroupList.add(me)

      end if


      end

      on mouseUp (me)


      -- inform the group that this button is clicked

      call(#GroupSelect, myGroupList, me)


      end



      on GroupSelect (me, whoIsSelected)


      -- a member of the group has been selected. If the selected

      -- object is this object, then hilight the button. Otherwise,

      -- turn the hilight off.

      if whoIsSelected = me then myState = 1

      else myState = 0

      sprite(me.spriteNum).member.hilite = myState


      end



      on GetPropertyDescriptionList (me)


      pdList = []

      pdList[#myGroupID] = [#Comment "GroupID", #default #RadioGroup, #Format
      #symbol]

      pdList[#myState] = [#Comment "Default State", #default 1, #Format #boolean]

      return pdList


      end


        • 1. Re: Radio button code
          Level 7
          Sorry guys
          What I meant was not the handler the whoIsSelected parameter.
          I dont know how a value is passed to that.

          any help would be appreciated
          thanx
          ahmed


          • 2. Re: Radio button code
            James Newton, ACP Level 3
            When you click on a button which has the behavior attached to it, this command is executed:

            call(#GroupSelect, myGroupList, me)

            In plain English, the on GroupSelect() handler is triggered on each of the sprites in the given radio button group, and a pointer (me) to the behavior which sent the #GroupSelect event is passed as a parameter.

            It looks as if you might want to set the selected radio button using Lingo rather than by having the user click on the button. If slightly modified your code so that the selected sprite is identified by its spriteNum rather than by a pointer to a behavior. With this revised code, you can use...

            sendAllSprites(#GroupSelect, <integer spriteNum>, <symbol groupID>)

            ... to select the radio button with the given spriteNum that is part of the group with the given groupID.

            • 3. Re: Radio button code
              Level 7
              hello openspark

              thanx for the help.

              the script doesnt give any errors but it does not work either.
              I can click all three radio butons and all of them are highlighted.
              I must be doing something wrong.

              thank you
              ahmed


              • 4. Re: Radio button code
                James Newton, ACP Level 3
                Are all three behavior instances set to use the same groupID? If you provide each with a different groupID in the Behavior Parameters dialog, each will act as a group of its own.

                Are you using "classic" radio buttons or the "default" (Flash component) radio buttons?

                Are you using a separate classic radio button member for each sprite?
                • 5. Re: Radio button code
                  Level 7
                  its the flash button from the tool bar (MX)
                  I have tried using separate members and instances of one member
                  I have same groupID.
                  It just wouldnt unchek the rest of the buttons.

                  thanx again for your help
                  ahmed


                  • 6. Re: Radio button code
                    James Newton, ACP Level 3
                    The behavior that you were using, and that I modified, is designed for "classic" radio buttons. It will not work with Flash Component buttons. You have three possible solutions:

                    1) Find out how to use the Flash Component buttons (something that I can't help you with)
                    2) Use classic radio buttons and the behavior I modified
                    3) Use your own custom bitmap members and the Radio Buttons behavior that you can find on my site.
                    • 7. Re: Radio button code
                      Lukewig Level 1
                      HI,

                      Your behaviour should work with Flash radio button components - but you might need to check the eventpassmode property of the Flash component (hilight the member or sprite, click on the 'Flash component tab" in the property inspector, and down the bottom check that 'eventpassmode' is set to 'passAlways')

                      -- Luke