Reusing buttons from another card

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
Natalie
Posts: 7
Joined: Sat Apr 28, 2012 12:07 am

Reusing buttons from another card

Post by Natalie » Tue May 01, 2012 5:32 am

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

dave_probertGA6e24
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 328
Joined: Mon Dec 05, 2011 5:34 pm
Contact:

Re: Reusing buttons from another card

Post by dave_probertGA6e24 » Tue May 01, 2012 7:54 am

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
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.

Steve Denney
Posts: 101
Joined: Wed Dec 22, 2010 8:17 pm

Re: Reusing buttons from another card

Post by Steve Denney » Tue May 01, 2012 8:03 am

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

Natalie
Posts: 7
Joined: Sat Apr 28, 2012 12:07 am

Re: Reusing buttons from another card

Post by Natalie » Tue May 01, 2012 9:59 pm

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10320
Joined: Wed May 06, 2009 2:28 pm

Re: Reusing buttons from another card

Post by dunbarx » Tue May 01, 2012 10:34 pm

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

Natalie
Posts: 7
Joined: Sat Apr 28, 2012 12:07 am

Re: Reusing buttons from another card

Post by Natalie » Wed May 02, 2012 2:22 am

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

Natalie
Posts: 7
Joined: Sat Apr 28, 2012 12:07 am

Re: Reusing buttons from another card

Post by Natalie » Wed May 02, 2012 3:38 am

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

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

Re: Reusing buttons from another card

Post by Klaus » Wed May 02, 2012 10:39 am

Hi Natalie,

1. welcome to the forum! :)

2.Please check these stacks, to get the hang on how LiveCode works even more 8)
http://www.runrev.com/developers/lesson ... nferences/


Best

Klaus

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

Re: Reusing buttons from another card

Post by mwieder » Wed May 02, 2012 5:34 pm

I think I'm starting to get the hang of how LiveCode works.
Yay! :P

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7392
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Reusing buttons from another card

Post by jacque » Thu May 03, 2012 4:31 pm

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. :)
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply