Friday 15 March 2019

Toggle button

One of the missing controls in Livecode palette is the toggle button.
To obtain a toggle button, just add this code to a button:


on MouseUp
   put the hilite2 of me into hitemp
   if hiTemp then
      set the hilite2 of me to false
   else
      set the hilite2 of me to true
   end if
end MouseUp

setprop hilite2 temp
   set the hilite of me to temp
   set the hilite2 of me to temp
end hilite2

I used a new property, because the hilite is actived as soon you press but you still don't relase the mouse.

1 comment:

  1. Thanks for the blog - i see it's been a couple of years since last updated, i hope you can keep this going...

    With respect to the code above: it works, but it causes a flicker on the default button. This is because the button property 'autohilite' is by default set to true.

    All you need to do is switch the autohilite property to false and then use 1 line of code:

    on mouseUp
    set the hilite of me to not the hilite of me
    end mouseUp

    ReplyDelete