Tuesday, May 21, 2024
 Popular · Latest · Hot · Upcoming
22
rated 0 times [  26] [ 4]  / answers: 1 / hits: 5242  / 9 Years ago, wed, january 6, 2016, 12:00:00

Using latest Fabric.js, I have the code:



var imageAdded = new Image();
imageAdded.onload = function (img) {
var imgAdded = new fabric.Image(imageAdded, {
clipName: picID,
clipTo: function (ctx) {
return _.bind(clipByName, imgAdded)(ctx)
}
});
canvas.add(imgAdded);

imgAdded.on(object:selected, function (e) { // It doesn't pass this function
alert(e.target.clipName + is selected);
e.target.clipTo = null;
canvas.renderAll();
});
};



  • I want to alert when I select an object but no alert is showed because the function where I made a comment in the code doesn't work.

  • I tried this link but still can't make it possible.



I appreciate every suggestion. Thank you!


More From » fabricjs

 Answers
6

If you want an event for a specific object use:



imgAdded.on(selected, function(){alert(this.clipName);});


if want event for canvas and all objects:



canvas.on(object:selected, function(e){alert(e.target.clipName);});

[#31792] Tuesday, January 5, 2016, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
gavenmekhio

Total Points: 732
Total Questions: 89
Total Answers: 93

Location: Central African Republic
Member since Mon, Aug 10, 2020
4 Years ago
;