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 .

Muhammad Usman
  • 10,426
  • 22
  • 72
  • 107
  • 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: http://www.html5canvastutorials.com/kineticjs/html5-canvas-select-shapes-by-name-with-kineticjs/ – Rikonator Dec 23 '12 at 10:52
  • 2
    Yep, what @Rikonator 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. – Scotty Jan 11 '13 at 11:38

2 Answers2

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.

SoluableNonagon
  • 11,541
  • 11
  • 53
  • 98
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).

aapdl
  • 1
  • 2