Help with adding button

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
hands16
Posts: 17
Joined: Sat Oct 19, 2013 2:23 am

Help with adding button

Post by hands16 » Tue Sep 30, 2014 3:03 am

Is there a way to add a single button to every card in an entire stack at the same time? and i don't already have a group of buttons i can just add the button to

sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Re: Help with adding button

Post by sefrojones » Tue Sep 30, 2014 3:18 am

This should work for you:

Code: Select all

   repeat with x = 1 to the number of cards in this stack
      if there is not a button "MyButton" of cd x then
          copy btn "MyButton" of cd "CardWithButton" to cd x
            end if
   end repeat
Hope that helps,

--Sefro

hands16
Posts: 17
Joined: Sat Oct 19, 2013 2:23 am

Re: Help with adding button

Post by hands16 » Tue Sep 30, 2014 3:30 am

i know this sounds dumb but where do i put that code?

hands16
Posts: 17
Joined: Sat Oct 19, 2013 2:23 am

Re: Help with adding button

Post by hands16 » Tue Sep 30, 2014 3:32 am

is there a way to place a group of buttons on every card in a stack at once?

sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Re: Help with adding button

Post by sefrojones » Tue Sep 30, 2014 3:38 am

Well, you could just make a new button, and add that script between the mouseup handler, also changing the names of the button/card to the ones in your stack. Once you press it it will automatically add the button to every card in your stack, then you can just delete the extra button once it has done it's work. To answer your second question: You can set up a group, and check off "behave like a background" in the property inspector/ Every card you create after that will have this group on it. If you already have the cards created (which it sounds like you do) you could easily create a group and use basically the same script I posted above to copy it to each card.

HTH,

--Sefro

Edit: I will, as others have before me, encourage you to check out these stacks : http://www.hyperactivesw.com/revscriptc ... ences.html
They contain a wealth of LiveCode knowledge. :D

sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Re: Help with adding button

Post by sefrojones » Tue Sep 30, 2014 5:12 am

This may be overkill, but I came up with this function:

Code: Select all

function CopyToAll tObjType,tObjName,tCDname
     put"if there is not a"&&tObjType&quote&tObjName&quote&"of cd x then" &cr into tScript
      put "copy"&& tObjType&quote&tObjName&quote&&"of cd"&&quote&tCDname&quote&&"to cd x" & cr after tScript
      put "end if" after tScript
repeat with  x = 1 to the number of cards in this stack
    do tScript
end repeat
end CopyToAll
You can throw this into your stack script, and then use it from the message box (or in a script) like this:

Code: Select all

copytoall("group","mygroup","CardWithMyGroup")
or

Code: Select all

copytoall("button","mybutton","CardWithMybutton")
or

Code: Select all

copytoall("graphic","mygraphic","CardWithMyGraphic")
This function will copy the referenced control to all cards in a stack that do not already contain one. I'm not sure if this is actually useful, and make no warranties, but I was bored and this is what I came up with :)

--sefro

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”