Dynamically creating buttons and events. Event did not work.


hi guys,

 

i trying create application dynamically create buttons , events....creating button not problem event did not work. code below simple... 1st click button , create button (dynamic).... if click newly created button should alert test2....

 

does knows how implement (that works )

 

<?xml version="1.0" encoding="utf-8"?>
<mx:application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:script>
        <![cdata[
       
    import mx.controls.*;
       
       
        private function onload():void
        {
            var btn:button = null;
            //
                test2();
                btn = new button();
                btn.label = 'test';
                btn.addeventlistener("click", test2);
                this.addchild(btn);           
        }
       
        private function test2():void
        {
            alert.show('test', 'testing');
        }       
       
       
         ]]>
     </mx:script>
    <mx:hbox id = 'testbox' x="0" y="154" width="100%">
        <mx:button label="button" click = 'onload();'/>
    </mx:hbox>
   
</mx:application>

hi gretags,

 

you forgot specify argument in eventlistener...thats why getting runtime script error..

 

check below code...now alert popup...

 

 

<?xml version="1.0" encoding="utf-8"?>
<mx:application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:script>
        <![cdata[
       
    import mx.controls.*;
       
       
        private function onload():void
        {
            var btn:button = null;
            //
                //test2();
                btn = new button();
                btn.label = 'test';
                btn.addeventlistener("click", test2);
                this.addchild(btn);           
        }
       
        private function test2(event:mouseevent):void
        {
            alert.show('test', 'testing');
        }       
       
       
         ]]>
     </mx:script>
    <mx:hbox id = 'testbox' x="0" y="154" width="100%">
        <mx:button label="button" click = 'onload();'/>
    </mx:hbox>
   
</mx:application>

 

if post answers question or helps, please kindly mark such.


thanks,

bhasker chari



More discussions in Flex (Read Only)


adobe

Comments

Popular posts from this blog

Gavik Photoslide GK2: Not able to upload photos - Joomla! Forum - community, help and support

How to decompile jsxbin to jsx

Phoca Guestbook logger registret bruger af - Joomla! Forum - community, help and support