Page 1 of 1

Radio Button Headache

Posted: Sun Aug 05, 2007 3:16 am
by Timothy
Bg btn "sequenced" and "un-sequenced" are radio buttons, and they are both background buttons. "Behave like Background" is turned on. Auto hilite and shared hilite are turned off.

I didn't want to put these buttons in their own group, because it didn't seem necessary. I thought I would just control the hilite with a script, instead. Also, I didn't want to bother to place the new group on a whole bunch of cards that existed before I made these buttons.

Script for bg btn "Sequenced"

Code: Select all

on mouseUp
  if the cantdelete of this card is "true" then
    answer "To change this setting, first unlock the lock icon."
    exit mouseup
  end if
  if the hilite of me is false then
    set the hilite of me to true
    set the hilite of bg btn "un-sequenced" to false
  end if
end mouseUp
Script for bg btn "un-sequenced"

Code: Select all

on mouseUp
  if the cantdelete of this card is "true" then
    answer "To change this setting, first unlock the lock icon."
    exit mouseup
  end if
  if the hilite of me is false then
    set the hilite of me to true
    set the hilite of bg btn "sequenced" to false
  end if
end mouseUp
If the cantdelete of the card is "false" everything works fine.

If the cantdelete of the card is "true" and I click on one of the radio buttons when the hilite is true, the hilite changes to false. I can see it change before I get the answer dialog.

Further experimentation shows that if the hilite of a radio button is true and I comment the script out, the hilite still changes to false. In that case, if the hilite is false, it stays false.

I made a new pair of buttons, this time as a separate group, so they will behave as a radio button family. They work the same way as the first pair. I.e., not the way I want to.

I tried various ways to script around this phenomenon, but couldn't come up with one.

It looks like the hilite of the radio buttons change on mouseDown rather than mouseUp

I tried trapping both the mouseDown and the mouseUp.

Code: Select all

On mouseUp
   if the cantdelete of this card is "true" then
    exit mouseup
  end if
if the hilite of me is false and the cantdelete of this card is not "true" then
    set the hilite of me to true
    set the hilite of bg btn "sequenced" to false
  end if
end mouseUp

on mouseDown
  if the cantdelete of this card is "true" then
    answer "To change this button, first unlock the lock icon."
    exit mouseDown
  end if
end mouseDown
Still no luck.

The debugger shows that the scripts are executing normally.

Apparently, it's not possible to alter the hilite behavior of a radio button with a script. As I recall, I could do that in hyperCard.

My questions:

1-How do I make these radio buttons behave as I want them to?

2-Is this a bug?

Thanks,


Tim


P.S. One thought -- I guess I could copy the icons of hilited and unhilited radio buttons and make them the icons of non-radio buttons. Then change the icons with a script. Would that work?

If so, how do I copy the icons of hilited and un-hilited radio buttons?

Posted: Sun Aug 05, 2007 12:28 pm
by Klaus
Hi Timothy,

you can controil what radiobutton gets hilited in a group by simply settting:
1. the hilitedbuttonname of grp xyz to "name of btn 2 be hilited" or
2. the hilitedbutton of grp XYZ to NUMBER _OF_BTN...

When you do this, the other radiobuttons in that group will automatically get unhilited, no other scripts necessary!
Maybe that is what you are after.

Try this to get a nice screenshot from radiobuttons.

Create one radiobutton (just for the screenshot!) and one or two images "rb1" and "rb2" and run this script:
...
set the hilite of btn "rb" to false
export snapshot from rect (the rect of btn "rb") of btn "rb" to img "rb1" as PNG
set the hilite of btn "rb" to true
export snapshot from rect (the rect of btn "rb") of btn "rb" to img "rb2" as PNG
...

Et voila, two nice png images.
You may set the "showname" of thje button to false.

Hope that helps.


Regards

Klaus

Posted: Sun Aug 05, 2007 5:08 pm
by Lynn P.
Hi Tim ~

If you have the buttons grouped and Behave like Background is turned on, then your code also works "as is", as long as you turn off the "RadioBehavior" of the group which will override your scripted behavior.

If you leave RadioBehavior turned on, then use the "set the hilitedButton" or "set the hilitedButtonName" approach and let Rev do the work for you as Klaus suggested.

Posted: Sun Aug 05, 2007 7:27 pm
by Timothy
Thanks Lynn and Klaus.

That took care of it.

Tim