I'm working on a small game that uses a bunch of buttons that perform
similar actions. In the main class for the game I've set up a
listener object ("gameButtonListener") to detect all the button
clicks and call the appropriate game functions, which are also
defined in the main class.
Here's a simplified version of the relevant code. (Broadcasting the
"buttonReleased" message is handled in the button's class.)
---
var gameBroadcaster:Object;
var gameButtonListener:Object;
AsBroadcaster.initialize(this.gameBroadcaster);
this.gameBroadcaster.addListener(this.gameButtonListener);
this.gameButtonListener.buttonReleased = function(b:MovieClip) {
doButtonClick(b);
}
private function doButtonClick(b:MovieClip):Void {
trace('button clicked!');
// do some other stuff with b's properties
}
---
The code above doesn't work, of course, because doButtonClick() is
not a method of the gameButtonListener object. right?
How should I be specifying the scope of the doButtonClick() function
in the anonymous function defined for the listener? Although "_root"
and "_level0" would work in a standalone situation I know they're not
good ideas (and the latter would break when the game's loaded into
another level), and "_parent" doesn't work with Objects the way it
does with MovieClips.
Thanks,
Jim
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders