I’m trying to rewrite a procedural ActionScript program as an OOP one: in the procedural version I set up event handlers for movieclips on the stage with a loop and it worked fine. However, when I put these event handlers in a class definition, it’s no good. Simplified version below, which is just supposed to make a sound when the user clicks on the box
class definition:
class Event_stuff {
var nLpCntr1:Number = 0;
var nNumberOfChoiceBoxes:Number = 3;
var sInstanceName:String = “”;
var bChoiceBoxFocus:Boolean = true;
function setUp_event_handlers () {
//level0.oSoundForClick.start();
for (nLpCntr1 = 1; nLpCntr1 <=nNumberOfChoiceBoxes; nLpCntr1 ++) {
sInstanceName = "choice" + nLpCntr1;
_level0 [sInstanceName].onRelease = makeNoise;
}
}
function makeNoise () {
if (bChoiceBoxFocus) {
_level0.oSoundForClick.start();
}
}
}
I use the next bit of code in an FLA file (with three movieclips with names choice_1 to choice_3 on the stage)
var myEvent1:Event_stuff = new Event_stuff ();
sSoundForClick = “twang”;
oSoundForClick = new Sound ();
oSoundForClick.attachSound (sSoundForClick);
myEvent1.setUp_event_handlers ();
but when I run it, no sound - the problem is that function makeNoise in the class definition doesn’t pick up that bChoiceBoxFocus is true (although if I cut the initialization of bChoiceBoxFocus at the beginning of the class definition it causes an error There is no property with the name ‘bChoiceBoxFocus’.
Any help greatly appreciated - I’m new to OOP stuff, so apologies for any wrong use of terminology