Get multiple objects from stage by class name in KineticJS
Asked Answered
S

2

6

I am using using JavaScript library Kinetic.js for HTML5 canvas. Here is the method stage.get() to get objects from stage (canvas). I have assigned the id's or class names to each object

if I get the object by id var obj = stage.get('#obj_id') it works but If try to get the multiple objects by class name var objs = stage.get('.obj_class_name') it returns an empty [] object

How I can get multiple objects from stage .

Succentor answered 23/12, 2012 at 7:39 Comment(2)
Can you please provide a bit more context? Some code of how you construct the objects and where you add them to the stage would be nice. Right now, it is difficult to understand where the problem lies, since stage.get('.object_name') should work, as specified here: html5canvastutorials.com/kineticjs/…Larine
Yep, what @Larine said - stage.get('.object_name') should work if you've defined the name parameter for each object. If you could provide a bit more context and/or a jsfiddle of your code.Invective
P
1

well, you could just do .getChildren() to get all children, then iterate through the array with a loop and a condition to add a new array you created.

Pericles answered 2/1, 2013 at 17:3 Comment(0)
S
0

You can use the name attribute. It works as the classin HTML. Use the stage/layer function find('.<name>') to select all your elements with the the name <name> (The dot is necessary).

Sensate answered 28/8, 2015 at 15:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.