ericdrowell / KineticJS

KineticJS is an HTML5 Canvas JavaScript framework that extends the 2d context by enabling canvas interactivity for desktop and mobile applications.
http://www.kineticjs.com
3.98k stars 753 forks source link

Dynamically set path mouse functions #1031

Open Gouvi opened 9 years ago

Gouvi commented 9 years ago

More of a question, apologies for not directing it in the correct forum, this repo is active and hopefully someone can help me. I am looking at setting multiple mouse callbacks.

for (var i = 0; i < somelength; i++) {
    path[i].on('mouseover', function() {//dostuff});
    path[i].on('mouseout', function() {//dostuff});
    path[i].on('mousedown', function() {//dostuff});
}

Just getting a TypeError: Cannot read property 'of' undefined. Manually setting the callback works fine.

path[0].on('mouseover', function() {//dostuff});

Path is simply a global array, I am setting each array element to a new Kinetic path:

path[i] = new Kinetic.Path({etc.});

Any help would be much appreciated.