3

Please help. I want to add a click event on checkbox that i created dynamically so that i know what checkbox I click.

Heres my code on action script:

var myCheckbox:CheckBox = new CheckBox(); vbox.addChild(myCheckbox);

How to add click event on checkbox?

Jejad
  • 289
  • 1
  • 6
  • 18

1 Answers1

4
private function myCheckboxClicked(event:MouseEvent)
{
    // doStuff();
}

...

myCheckbox.addEventListener(MouseEvent.CLICK, myCheckboxClicked); 

As long as it inherits EventDispatcher, you can attach a listener and it'll send events as normal.

LiraNuna
  • 64,916
  • 15
  • 117
  • 140
  • Thank you for your response. Upon implementing your solution, I've got this error. 1067: Implicit coercion of a value of type void to an unrelated type Function. What is lacking? I put import flash.events.MouseEvent; – Jejad Feb 20 '09 at 09:27
  • You can also be more specific and specify the return type of the function like so: private function myCheckboxClicked(event:MouseEvent):void – erikprice Feb 20 '09 at 12:04