Site Navigation
vegUI Tutorial 04 - Cloning
written by vegu on 18 Dec, 2006 10:14:56
A live example of this tutorial can be found
hereThis tutorial is a follow-up tutorial to
tutorial 3.
Until any vegUI element is built it is seen as a template object. Template objects can be used to spawn duplicate objects that take over the template's properties entirely. This comes in handy if you have - for example - a green button that when click alerts a message, and now you want to use that button 4 times on your web application - for whatever reason.
So instead of re-defining and re-setting the same button object four times you can just define it once and clone it 3 times. This
reduces the amount of code needed to get the project done and also speeds up script execution.
Lets take our 'myNode' object from previous tutorials and make sure it is not built. The easies way to get a cloned object is by using the Manager's get_clone() method. Alternatively you can also call the clone() method on the element directly.
var clonedNode1 = Manager.get_clone(myNode);
clonedNode2 = Manager.get_clone(myNode);
Definition: VegUIManager.get_clone()If we build clonedNode1 and clonedNode2 now they should both have the properties and child elements that we defined for myNode earlier.
Alternative way of cloning
As i said you can also call the clone_node() or clone() method on the object directly, you needs if you want an object that exists already to take over the properties of another project. Keep in mind that both objects need to be unbuilt though.
var clonedNode1 = Manager.get_new(VUI_NODE);
clonedNode1.clone(myNode);
Definition: VegUINode.clone_node()Thats pretty much all there is to cloning, the next tutorial will deal with handling mouse and keyboard events.
Related Posts
Your Comment
Comments
No comments yet.