0

In my applications I have to generate a button dynamically and have to keep a click handler for the same. How to write script for clicking button?

I'm using following code for creating button dynamically

var btn:Button = new Button;
btn.label = "Print";

whats for click?

2 Answers 2

1
btn.addEventListener(MouseEvent.CLICK,myfun);

write your code in myfun function.

Sign up to request clarification or add additional context in comments.

1 Comment

Isn't mxml nice? click="myfun()" is so much easier to type, and you can control whether you want to bother with an event parameter! Of course it doesn't help in this dynamic UI case, but non-Flex devs should take notes here. =)
1
btn.addEventListener(MouseEvent.CLICK, onClick)

...

private function onClick(evt:MouseEvent)
{
    trace("click");
}

About handling events

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.