Hi Jason,
in a situation like this i first determine if Button is a dynamic class...if it
is i designate a variable and assign it the parent class to it like this
myButton.parentObj = this;
this way i can call any function that's a memeber of the parent class like so...
myButton.onRelease = function() {
this.parentObj.doSomething();
}
if it's not a dynamic class then you can either hack it to be or design another
call back mechanizm
hope this helps
b
----- Original Message ----
From: Jason Boyd <[EMAIL PROTECTED]>
To: [email protected]
Sent: Sunday, February 4, 2007 1:56:39 PM
Subject: [Flashcoders] hooking up GUI in pure OO code...
OK this is making me nuts. It seems to be an impossible scope problem,
to do something that ought to be very very possible, and in fact
common. The basic problem: I want to have initialization code in a
Main class that hooks up GUI controls to methods in this class (acting
as a controller class essentially). For various reasons, I do not want
to use components; the GUI elements are either Buttons or MovieClips.
Again, this ought to be possible, right?
So here's the problem case:
class Main {
var myButton:Button; // placed on stage in authoring time
function init() {
myButton.onRelease = function() {
doSomething();
}
}
function doSomething() {
trace("something");
}
}
This does not work, nor is there any way I can wrap my head around
getting it to work, as the anonymous function assigned to the button
event handler has "this" scoped as the button itself, so
"doSomething()" refers to a non-existent function
myButton.doSomething(). Simply assigning the member function to the
button event handler directly doesn't help, as this function is then
unable to call other member functions for the same reason. E.g.:
function init() {
myButton.onRelease = doSomething();
}
function doSomething() {
// this will be called now, but "this" still refers to the button,
not objects of this class
}
There has *got* to be some way around this issue. Right?
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com