PDA

View Full Version : Buttons in a class


MisterMister
02-19-2005, 08:38 PM
Well I've searched the forums and I haven't found anything about this, or it's been a really complicated even listener model. I need to set a onRelease for a button in my script but I'd like to do it from my GUI class. For instance

class test {
var button1;
var button2;

public function setbutton1 (button1){
button1 = button1;
}
pubic function button1.onRelease() {
doSomething();
}
}


I know that this code doesn't work, but you get the gist. Is there an easy way to do this. I'm trying to wrap up my GUI in a class. I know that I could just sit it outside my class, but I'd like to keep it organized in a class.

Thanks,
MisterMister

pcarini
02-19-2005, 10:53 PM
You might try this, (I'm not 100% sure)

class test
{
var button1;
var button2;

public function setbutton1 (btn)
{
button1 = btn;
button1.onRelease = function()
{
// do something
}
}

MisterMister
02-21-2005, 03:22 AM
Thanks, this worked perfectly. This is exactly what I was looking to do. And it only works after the method is invoked, which is exactly what I wanted and expected.

Thanks again