Kineticjs Tutorials (9)

Source: Internet
Author: User

Kineticjs Tutorials (9)Author: ysm 9. Selector

Kinetic provides a Get method on stage, layer, and group objects to return the objects contained in the three.

9.1. According toID Get Object

To get an object with an ID, first assign an ID to the object , such as the ID of the rect created by the following code is id1:

<script>

var rect = new kinetic.rect ({

ID: "id1"

});

</script>

Note that theID is unique, and different objects cannot use the same ID, otherwise get can only return one of them.

Then, with the get method, theID selector "#" gets the object for the parameter:

<script>

var obj = stage.get (' #id1) [0];

var obj = layer.get (' #id1) [0];

var obj = group.get (' #id1) [0];

</script>

This place to note that this get returns an array, even if the ID is unique, so to get the object you want, you must bring the index of the array.

9.2. Get objects by name

To get an object by name, first give the object a name , such as the name of the rect created by the following code is name1:

<script>

var rect = new kinetic.rect ({

Name: "name1"

});

</script>

Unlike IDs,name is not unique, and different objects can share the same name.

Then use the get method, theID selector "." To get an object for a parameter:

<script>

var Objs = Stage.get ('. name1′);

var Objs = Layer.get ('. name1 ');

var Objs = Group.get ('. name1 ');

</script>

This place to note that this get returns an array that contains all the objects called this name.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.