Re: [Proto-Scripty] Prototype Class, Event Listeners and Referencing Self

2010-07-21 Thread Guillaume Lepicard
Hi, you need to bind the listener function to your object:
 
$('box').addEventListener("click",this.takeAction.bindAsEventListener(this),false);

more details:
http://api.prototypejs.org/language/function/prototype/bindaseventlistener/

On Tue, Jul 20, 2010 at 7:13 PM, Doc Torbin  wrote:

> I have the following snippet of code which illustrates a problem that
> I'm having.  I have an event listener within a class that I'd like to
> have be "self aware".  I'd like it to be able to call another function
> within the Class but I haven't found the right method to have it do
> so.  Please advise:
>
> 
> 
>
> src="../prototype.js">
>
>#box{position:fixed;width:100px;border:3px solid
> #000;background-
> color:#00ff00;font-size:14pt;font-weight:bold;text-
> align:center;padding:50px 25px;cursor:pointer;}
>
>
>var MyOBJ = new Class.create();
>MyOBJ.prototype = {
>initialize: function(){
>try{
>
>  $('box').addEventListener("click",this.takeAction,false);
>}
>catch(error){alert(error);}
>},
>takeAction: function(event){
>alert("I got to this function
> without issue.");
>this.anotherAction();
>},
>anotherAction: function(){
>alert("I won't get here.");
>}
>}
>
>document.observe("dom:loaded", function(){
>var spriteOBJ = new MyOBJ();
>});
>
>
>
>BOX
>
> 
>
> --
> You received this message because you are subscribed to the Google Groups
> "Prototype & script.aculo.us" group.
> To post to this group, send email to
> prototype-scriptacul...@googlegroups.com.
> To unsubscribe from this group, send email to
> prototype-scriptaculous+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/prototype-scriptaculous?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.



[Proto-Scripty] Prototype Class, Event Listeners and Referencing Self

2010-07-21 Thread Doc Torbin
I have the following snippet of code which illustrates a problem that
I'm having.  I have an event listener within a class that I'd like to
have be "self aware".  I'd like it to be able to call another function
within the Class but I haven't found the right method to have it do
so.  Please advise:






#box{position:fixed;width:100px;border:3px solid 
#000;background-
color:#00ff00;font-size:14pt;font-weight:bold;text-
align:center;padding:50px 25px;cursor:pointer;}


var MyOBJ = new Class.create();
MyOBJ.prototype = {
initialize: function(){
try{

$('box').addEventListener("click",this.takeAction,false);
}
catch(error){alert(error);}
},
takeAction: function(event){
alert("I got to this function without 
issue.");
this.anotherAction();
},
anotherAction: function(){
alert("I won't get here.");
}
}

document.observe("dom:loaded", function(){
var spriteOBJ = new MyOBJ();
});



BOX



-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.