Page 1 of 1
Reusing buttons from another card
Posted: Tue May 01, 2012 5:32 am
by Natalie
Hello,
I have some buttons that were created on different cards, and I want to reuse them on a new card. Is there any way I can get them to be recognized from the new card?
Thanks,
=Natalie
Re: Reusing buttons from another card
Posted: Tue May 01, 2012 7:54 am
by dave_probertGA6e24
You can copy them to your card with:
copy button "xyz" of card "asd" to card "qwe" -- copy it from the source card to a new card
set the name of it to "new_name_of_button" -- give it a new name
set the loc of it to the loc of button "xyz" of card "asd" -- copy its original location
I hope that helps.
Dave
Re: Reusing buttons from another card
Posted: Tue May 01, 2012 8:03 am
by Steve Denney
Hi Natalie, any number of ways to do this. (Okay, I've just seen Dave has already replied but I've spent 10 minutes typing so i'm posting anyway)
You could simply copy & paste the buttons. Like, from one card to another, or from one stack to another. This works with whole cards too (you can copy a card from one stack to another). To select a whole card go to the object menu and choose card inspector. Then you will find copy card in the edit menu. To select an object like a button choose the pointer tool then click on that object to select it. Then go to the edit menu. Note the edit menu shows the keyboard short cuts too (well worth knowing).
Sorry if I'm telling you stuff you already know.
You could also use code, either in a custom procedure/command/function (e.g. on copyMyBtns) or from the message box...
Type ctrl (or apple) m to bring up the message box (or go to the tools menu). Then type:
copy btn buttonName --or copy btn number, then hit enter
-- then you can go to your new card and type
paste
Or you can do it all in one go (can use either numbers or names of buttons & cards)...
copy btn 1 of cd 1 of stack "oldStak.livecode" to cd 1 of stack "newStak.livecode"
--You could use the above code from either stack as long as both stacks were in the same folder (little more work needed if they're not -- you'd need to specify the file path). Actually you could use that code from any stack in that folder.
Oh, and you substituted the right names, numbers, of course.
Hope this is what you're after
Steve
Re: Reusing buttons from another card
Posted: Tue May 01, 2012 9:59 pm
by Natalie
Thanks, Steve and Dave. I hope the memory usage will be smaller, by copying, and that it won't duplicate the graphics into the new card. That was my main concern.
=Natalie
Re: Reusing buttons from another card
Posted: Tue May 01, 2012 10:34 pm
by dunbarx
Hi.
All the responses deal with an object on one card that is to be copied to another card. If you read the suggestions, they should make perfect sense. This is a good thing.
But a more general solution, where you might want an object to be copied to new cards automatically, that is, as if they belonged to a higher level of ownership, is to make that object (or several objects) into a group. There is a property of groups known as the "backGroundBehavior" that, once set, will copy those objects as a matter of course, since they have a more exalted status.
So if you test this, making an object into a group, setting that property, and then create a new card, the group will automatically appear on that new card. It is a little more effort to take existing objects and similarly copy them to other cards, even if they have been grouped as above. The difference is when they are grouped, before or after the new cards are made.
Try it. The idea of a backGround is one of the oldest and most powerful features of this sort of environment; it was invented by Hypercard back in the Pleistocene.
Craig Newman
Re: Reusing buttons from another card
Posted: Wed May 02, 2012 2:22 am
by Natalie
Hi Craig,
I actually have 4 cards, with 4 buttons each. I would like the new card to be able to display one button from each of the groups. I haven't figured out how to make a group of groups. How would I do that?
Thanks,
=Natalie
Re: Reusing buttons from another card
Posted: Wed May 02, 2012 3:38 am
by Natalie
Oops, I just figured out that I don't really want to copy the buttons. I want the graphics on the button, the icon. So I found the icon, and set it to the button on the new card. I think I'm starting to get the hang of how LiveCode works.
Thanks,
=Natalie
Re: Reusing buttons from another card
Posted: Wed May 02, 2012 10:39 am
by Klaus
Hi Natalie,
1. welcome to the forum!
2.Please check these stacks, to get the hang on how LiveCode works even more
http://www.runrev.com/developers/lesson ... nferences/
Best
Klaus
Re: Reusing buttons from another card
Posted: Wed May 02, 2012 5:34 pm
by mwieder
I think I'm starting to get the hang of how LiveCode works.
Yay!

Re: Reusing buttons from another card
Posted: Thu May 03, 2012 4:31 pm
by jacque
There's a critical mass of info required, and until that all falls into place everything is like, "wha...???" and after it falls into place, it's like "oh sure, of course."
Sounds like you may have reached that point.
