I've been experimenting with creating a method in KineticJS. Here's the code I added:
Kinetic.Circle.prototype.test = function(){
alert(1);
}
It works well for circles, but now I'm trying to extend this method to work for layers and more. So I attempted the following code:
Kinetic.Node.prototype.test = function(){
alert(1);
}
However, I encountered an error in my console: Uncaught TypeError: Object # has no method 'test'.
I tried searching for a solution on Google, but couldn't find one.
@EDITED For Bergi :) I have an array containing layers where I create a Kinetic.Layer object within layers[layer_name].object like so:
layers.names[name]={
id:variable,
object:new Kinetic.Layer()
};
stage.add(layers.names[name].object);
Yes, the stage is created before in this code:
var stage=new Kinetic.Stage({
container:'canvas',
draggable:true,
height:document.documentElement.clientHeight,
width:document.documentElement.clientWidth
});
After that, I add a point to my object in the array:
var point=new Kinetic.Circle({
fill:'#000',
radius:3,
x:parent.children('input[name="x"]').val(),
y:parent.children('input[name="y"]').val()
});
var layer_name=$('input[name="layer"]').val();
layers.names[layer_name].object.add(point).draw();
At this point, I attempt to run my method:
var layer_name=$('input[name="layer"]').val();
var point=layers.names[layer_name].object.children[$('input[name="element_index"]').val()];
point.test();
Unfortunately, all I see in the console is the error mentioned earlier.