Page 1 of 1

How to create button at run-time in livecode

Posted: Thu Dec 22, 2011 3:00 am
by QuangNgo
Hi all,

I'm developing an application by using Live code. My ideas is I have "parent" button and It will generate 10 buttons after I had clicked on "parent" button.
then as I clicked on each "child" button it will give a popup "Button 1 is clicked !". It's quite simple right but I don't know how my code is doesn't work.

Code: Select all

 
    on mouseUp
    repeat with x=1 to 10 
      new button x
      add 30 to y
      set the width of button x to 50
      set the height of button x to 25
      set the location of button x to 50,50+y    --x,y location
    end repeat
   end mouseUp
It works but so weird.
I have the attached files in case you guys want to see
I think my code is not so good. Hope you guys give me to fix it

Regards,
Quang

Re: How to create button at run-time in livecode

Posted: Thu Dec 22, 2011 7:12 am
by mwieder
It's a bad idea to give buttons numeric names. If you already have a button 1 on the card that you're pressing to create new buttons, you don't want to create a new button and give it the name "1". That will confuse things when you get to statements like "set the width of button x to 50"... that's your creating button, not the button that you created.

Better to say something like

Code: Select all

new button "btn" & x
and then refer to button "btn" & x in the later statements.

Re: How to create button at run-time in livecode

Posted: Wed Dec 28, 2011 9:39 am
by QuangNgo
Hi mwieder,

Thank you a lot . Sorry to reply late. I've been back from my trip

Regards,
Quang