# Event handlers in a class definition

**URL:** <https://forum.kirupa.com/t/event-handlers-in-a-class-definition/208060>\
**Category:** Uncategorized\
**Created:** [November 24, 2006, 2:41pm UTC](https://forum.kirupa.com/t/event-handlers-in-a-class-definition/208060 "2006-11-24T14:41:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![euromarsup](https://avatars.discourse-cdn.com/v4/letter/e/4af34b/32.png) [@euromarsup](https://forum.kirupa.com/u/euromarsup)\
**Post date:** [November 24, 2006, 2:41pm UTC](https://forum.kirupa.com/t/event-handlers-in-a-class-definition/208060/1 "2006-11-24T14:41:55Z")

</div>

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_
