4 Replies Latest reply on Mar 21, 2007 6:03 AM by James Newton, ACP

    help with script to only allow one radio button

    ajrobson
      i have made a simple script that checks to see if a radio button is selected or not, if more then one is picked it turns the hilite of the others off. The problem is i have 28 radio buttons over 7 scenes i want to allow one button to be on from each scene but the way my code works now is it turns off every button apart from the last one choosen. Is there a way to do this has one behaviour or do i need to have a altered version on each scene?

        • 1. Re: help with script to only allow one radio button
          ajrobson Level 1
          anybody? the only other way i can think of doing this is by having a script on each scene so radio buttons will be q1A - q1D and do that for each question.
          • 2. Re: help with script to only allow one radio button
            johnAq Level 1
            There are many ways to do this - one way or the other you need to group the buttons

            1) Based on your example you could simply use the member names for grouping - instead of just comparing the name of the clicked member, compare whether or not char[2] of the name is the same as the clicked member. If so, deselect.

            2) You have the me parameter in your code, which suggests you are writing a behaviour which is attached to each radio on the stage. You could use sendAllSprites from the clicked member to tell other members to deselect. This way it will only affect any other radios on stage at the time and you don't need to hard code. Something like (pseudo-code)

            on mouseUp me
            clickedName = sprite(me.spriteNum).member.name
            sendAllSprites(#radioclicked, me, clickedName )
            end

            on radioclickedme, clickedName
            if sprite(me.spriteNum).member.name = clickedName then
            sprite(me.spriteNum).member.hilite = 1
            else
            sprite(me.spriteNum).member.hilite = 0
            end if
            end


            hth

            johnAq
            • 3. Re: help with script to only allow one radio button
              johnAq Level 1
              I just realised you don't need the me parameter in sendAllSprites

              sendAllSprites(#radioclicked, clickedName )

              hth

              johnAq
              • 4. Re: help with script to only allow one radio button
                James Newton, ACP Level 3
                There is a behavior named "Radio Button Group" in the Controls pane of the Library Palette. Here is an extract of its description:

                Select a group of radio button sprites and drop this behavior onto one of them. You will be asked to give a unique ID to the group so that its members can recognise each other.

                When the movie is running, switching one button in the group ON will switch all the others OFF. By default, the button in the lowest sprite channel will be ON...

                If you want to use your own graphics for the radio buttons, then you could try the behavior which you can find at http://nonlinear.openspark.com/tips/scripts/button/