Hi there,
how can I duplicate an object at runtime with all parameters?
Duplicate objects at runtime?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: Duplicate objects at runtime?
Enter 'template' into the dictionary... you will see that you can set the properties for a button, field, card etc before you create one of these... also have a look at 'clone' as this too might help you here...
Dixie
Dixie
-
- Posts: 216
- Joined: Wed Feb 27, 2013 9:04 pm
Re: Duplicate objects at runtime?
Ok, thank you.
I think 'clone' is what I need.
If I clone an object, how can I distinguish them?
In other programming languages I would create the duplicate with help of a new instance-variable. Such as x = y. So x would be a duplicate of object y.
If I write 'clone y' there's a clone of y, but how can I handle it?
I think 'clone' is what I need.
If I clone an object, how can I distinguish them?
In other programming languages I would create the duplicate with help of a new instance-variable. Such as x = y. So x would be a duplicate of object y.
If I write 'clone y' there's a clone of y, but how can I handle it?
-
- Livecode Opensource Backer
- Posts: 328
- Joined: Mon Dec 05, 2011 5:34 pm
- Contact:
Re: Duplicate objects at runtime?
Hi,
By using 'it' - the variable called 'it' will contain the long ID of the new cloned object.
for example:
The 'it' variable is used all over the place in LC, but it's only mentioned in the docs using one line in most cases - easy to overlook.
Hope that helps,
Dave
By using 'it' - the variable called 'it' will contain the long ID of the new cloned object.
for example:
Code: Select all
clone button "foo"
set the name of it to "bar"
set the loc of button "bar" to 100,100
Hope that helps,
Dave
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.
Visit http://electronic-apps.info for released App information.
Re: Duplicate objects at runtime?
Hi.
Know also that the "last" keyword might be helpful here, if you intend to grab that last created object and work with it. Be careful, though, as the "last" keyword is not stable when cloning groups, though it works with all other object types. The dictionary has a user note, ahem, by me...
Craig Newman
Know also that the "last" keyword might be helpful here, if you intend to grab that last created object and work with it. Be careful, though, as the "last" keyword is not stable when cloning groups, though it works with all other object types. The dictionary has a user note, ahem, by me...
This is not an issue with other objects,....The "last" keyword is not stable when referring to groups. So if one creates several groups, referencing the "last" group may not return the group actual ly created last. Using the "templateGroup" is a workaround, since when creating a new group one can, for example, set the name of the templateGroup to something unique, and be able to find the last group by name. Also, trapping the "newGroup" message with an appropriate script can be used to find the last group....
Craig Newman