dynamic Button captions?

dynamic Button captions?

bhnh
Advocate Advocate
506 Views
7 Replies
Message 1 of 8

dynamic Button captions?

bhnh
Advocate
Advocate
Anyone know if there's a way to change the caption on a Button when it's pressed? I'm thinking of a Boolean-type situation, where clicking the Button alternates the Boolean state between true and false. So the caption would read "Click for true" or "Click for false" depending on the Boolean state. Many thanks.
0 Likes
507 Views
7 Replies
Replies (7)
Message 2 of 8

bhnh
Advocate
Advocate
Problem solved...
(
rollout test "test" (

button pressthis "Press for true"

on pressthis pressed do
(
text1 = pressthis.text
if text1 == "Press for true" then
(
pressthis.text = "Press for false"
)
else pressthis.text = "Press for true"
)
)
createdialog test
)
0 Likes
Message 3 of 8

Steve_Curley
Mentor
Mentor
You can also toggle a boolean value rather than testing for the text - text tests are very slow in comparison to a boolean test.

I posted an example of just that (changing a button caption) not long ago, but I cant remember which thread it was in.

Found it - here - Post #3

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 4 of 8

bhnh
Advocate
Advocate
Found it - here - Post #3

Jeezum! Just goes to show how closely I pay attention :roll: . Before seeing your edit I tried this, with success...
rollout test "test"
(
button btn "Apples"
local bState = false

on btn pressed do
(
bState = not bState
if bState == true then btn.caption = "Oranges"\
else btn.caption = "Apples"
)
)
createDialog test 200 50

Thanks, Steve!
0 Likes
Message 5 of 8

Steve_Curley
Mentor
Mentor
Hehe - easy done Bruce. 🙂

Btw, you don't need the "= True" - it's a boolean value so just " if bState" (or "if not bState") is sufficient 😉

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 6 of 8

bhnh
Advocate
Advocate
Cool. Thanks. I'm making such an effort to keep MXS syntax separated from ActionScript syntax in my head, I tend to overlook instances where they're the same.
0 Likes
Message 7 of 8

bhnh
Advocate
Advocate
I suppose this is obvious, but I just realized this method can also make labels dynamic...

rollout test "Dynamic Label"
(
label lbl "Apples"
button btn "Comparison"
local Lstate = false

on btn pressed do
(
Lstate = not Lstate
if Lstate then lbl.text = "Oranges" else lbl.text = "Apples"
)

)

createDialog test
0 Likes
Message 8 of 8

Steve_Curley
Mentor
Mentor
Yep. You should be able to change any property that you can access, so you can enable/disable another button or group of items, reset the position of a progressbar, even move items around on the rollout (confusing for the user, but fun 😄 ), add items to drop-down lists - anything really which depends on a "what state am I in" type test.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes