Dynamic creation of buttons and events. Event was not working.

Hi guys,.

I am trying to create an application that will dynamically create buttons and events... Creating a button isn't a problem, but the event did not work. The code below is simple... 1. click on the button and it will create another button (dynamic)... If you click on the newly created button it should alert a test2...

Anyone know how to implement this (which works )

<? XML version = "1.0" encoding = "utf-8"? >
" < = xmlns:mx mx:Application ' http://www.Adobe.com/2006/MXML "layout ="absolute"> "
< mx:Script >
<! [CDATA]

Mx.controls import. *;

private void onLoad (): void
{
var btn:Button = null;
//
Test2();
BTN = new Button();
BTN.label = "test";
btn.addEventListener ("click", test2);
this.addChild (btn);
}

private void test2 (): void
{
Alert.Show ('test', 'test');
}

[]] >
< / mx:Script >
< mx:HBox id = "testbox.foobar.com" x = "0" y = "154" width = "100%" >
< mx:Button label = "click" = "onLoad()"; / >
< / mx:HBox >

< / mx:Application >

Hi gretags,

You forgot to specify the argument in the eventListener... that's why you are getting the runtime script error...

Check the code below... Now the alert will appear...


http://www.Adobe.com/2006/mxml"layout ="absolute">
   
               
Mx.controls import. *;
       
       
private void onLoad (): void
{
var btn:Button = null;
//
Test2();
BTN = new Button();
BTN.label = "test";
btn.addEventListener ("click", test2);
this.addChild (btn);
}
       
private void test2(event:MouseEvent):void
{
Alert.Show ('test', 'test');
}
       
       
]]>
    

   
       
   

   

If this post answers your question or assistance, please mark it as such.

Thank you

Jean Claude Chari

Tags: Flex

Similar Questions

Maybe you are looking for

  • Logon Windows XP takes a long time

    We have a Tecra M3 that is running windows XP. It takes about 3 minutes to type the login name to the display of the desktop - the laptop is set up to connect to our domain and everything seems to get more and more slow to log in - if you leave it at

  • HP Pavilion ZT 1000 wireless card or usb wifi?

    I have an old 1000 ZT iv had a new present, I don't think that it has wifi or wireless internet. I m woundering if getting a usb wifi is good or get the wireless card would be best? I need the computer connecting to the wifi at school and is everythi

  • T60 camera?

    Hello made all t60 don't have the camera?

  • Vostro 3550 restarts automatically (loop) every 3 seconds

    Dell support, I have a problem with a laptop Vostro 3550. When I turn on the laptop, it just is not started at all but it auto resarts at the same time, every 3 seconds, the screen is black.  The food, fan button, 3 buttons and also the front power i

  • Mss32.dll is missing

    Me too... BUT I INSTALL TNE NFS MOST WANTED REPLY............................... ME TO ANSWER... Thank you!