tags:

views:

321

answers:

2

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?

+3  A: 
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
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
I edited the answer appropriately
LiraNuna
Thank you so much...
Jejad
You can also be more specific and specify the return type of the function like so:private function myCheckboxClicked(event:MouseEvent):void
erikprice
A: 

Thanks a lot Lira.