View Single Post
Old 11-12-2012, 02:26 PM   PM User | #1
Ben Stuijts
New to the CF scene

 
Join Date: Nov 2012
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
Ben Stuijts is an unknown quantity at this point
Question OOP: adding Event to an Javascript object

I want to add an eventlisterer 'click' to an object, which is represented to the user as image. This wouldn't work, but shows what i want to achieve:

function object {
this.picture = null;
this.src = 'images/defualt.png';
this.id = 1;
this.setImage(this.src);
}

object.prototype.setImage = function(src) {
this.picture = new Image();
this.picture.src = src;
this.picture.addEvenListener('click' , clickme, false);
}

clickme = function() {
alert('hurray, i'm clicked...');
}
Ben Stuijts is offline   Reply With Quote