Changing button-icons via script?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Tomka
Posts: 59
Joined: Mon Apr 18, 2011 7:30 pm

Changing button-icons via script?

Post by Tomka » Sun May 15, 2011 6:32 pm

Hello,

I got a little script-problem. There are 2 buttons "Man" and "Woman"... if you click on one, it will be highlighted and the icons of the other button shall be changed.

Script of the first button (named: "Button_mann_0") :

Code: Select all

global g_neueperson_sex

on mouseUp
   if g_neueperson_sex<>"mann" then //checks if its allready activated
      put "mann" into g_neueperson_sex
      set the icon of the btn "Button_frau" to ID 10012
      set the hovericon of btn "Button_frau" to ID 10013
       set the armedicon of btn "Button_frau" to ID 10012
   end if
end mouseUp
The id´s refer to pictures on an other substack, where I imported the pictures as controls. If i push the button, following error appears:
button "Button_mann_0": compilation error at line 6 (if: not a command) near "10012", char 48
Maybe important: The buttons are on a seperate substack which is opened via filepath during execution. (Want to be able to save this substack later in a file)

Thanks for help :)

dglass
Posts: 519
Joined: Thu Sep 24, 2009 9:10 pm
Contact:

Re: Changing button-icons via script?

Post by dglass » Sun May 15, 2011 6:37 pm

The dictionary has this:

set the hovericon of button "Play" to 210095

there is no 'ID', perhaps that is the problem?

doc
Posts: 148
Joined: Fri Jun 09, 2006 4:30 pm

Re: Changing button-icons via script?

Post by doc » Sun May 15, 2011 6:47 pm

Since you are storing the images in a different stack, I'm pretty sure that the error indicates that the engine cannot locate your image... so try something like this:

Code: Select all

set the icon of the btn "Button_frau" to 10012 of stack "otherstackname"
HTH,
-Doc-

Tomka
Posts: 59
Joined: Mon Apr 18, 2011 7:30 pm

Re: Changing button-icons via script?

Post by Tomka » Sun May 15, 2011 7:04 pm

I tried:

Code: Select all

global g_neueperson_sex

on mouseUp
   if g_neueperson_sex<>"mann" then
      put "mann" into g_neueperson_sex
      set the icon of the btn "Button_frau" to image "weiblich_button_0.png" of stack "Untitled 2"
      set the hovericon of btn "Button_frau" to  image "weiblich_button_1.png" of stack "Untitled 2"
      set the armedicon of btn "Button_frau" to  image "weiblich_button_0.png" of stack "Untitled 2"
      
      set the icon of me to image "männlich_button_1.png" of stack "Untitled 2"
      set the hovericon of me to  image "männlich_button_0.png" of stack "Untitled 2"
      set the armedicon of me to  image "männlich_button_1.png" of stack "Untitled 2"
      
   end if
end mouseUp
Theres no error but if I push the button the buttons will be invisible. The property manager says icon-property = "0" and so on... Doesnt work it seems, other ideas? :)

Edit: In the property manager I can use the IDs to change the icons. So it shouldnt be a problem that pictures are on an other substack.

doc
Posts: 148
Joined: Fri Jun 09, 2006 4:30 pm

Re: Changing button-icons via script?

Post by doc » Sun May 15, 2011 7:10 pm

Go back to the version using the icon ID (10012) but without actually adding the "ID" as dglass indicated...
...but adding a reference to the stack where the image is located, as shown in my example.

-Doc-

Tomka
Posts: 59
Joined: Mon Apr 18, 2011 7:30 pm

Re: Changing button-icons via script?

Post by Tomka » Sun May 15, 2011 7:18 pm

No errors, no changes when i push the button.

Think that will be to complicated. I ll use 2*2 buttons and use visible/invisible :)

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Changing button-icons via script?

Post by Klaus » Sun May 15, 2011 9:14 pm

Hi Tomka,

do this:
...
set the icon of the btn "Button_frau" to THE ID of image "weiblich_button_0.png" of stack "Untitled 2"
...

Best

Klaus

Post Reply