How to create button at run-time in livecode

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
QuangNgo
Posts: 60
Joined: Thu Mar 31, 2011 8:31 am

How to create button at run-time in livecode

Post by QuangNgo » Thu Dec 22, 2011 3:00 am

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
Attachments
TestBehaviour.JPG

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

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

Post by mwieder » Thu Dec 22, 2011 7:12 am

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.

QuangNgo
Posts: 60
Joined: Thu Mar 31, 2011 8:31 am

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

Post by QuangNgo » Wed Dec 28, 2011 9:39 am

Hi mwieder,

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

Regards,
Quang

Post Reply