Hello All,

I'm tryin' to add some TextInputs dynamically in a FormItem by calling a
custom HBox component where the textinput is. To manage this I also create
dynamically a button in this custom component to add or remove the
corresponding component (textinput).
It's not far working but after a certain number of adds and removes,
I get the "range error: index out of bounds..."

I've been breaking my head for two days on this and can't figure out
how to solve it.

I would appreciate a little bit of help on this code, or maybe a link
to this kind of thing, I'm sure somebody has done this already,
but I didn't find anything on the web.

Thx for help.

        [Bindable]
        private var i:int;
        private var ajout:MailAjoutHBox;
        [Bindable]
        private var btn_ajout:Button;
        [Bindable]
        private var idAjoutArray:Array = new Array();
        [Bindable]
        private var idBtnArray:Array = new Array();
        
        
        private function minusAmisMail():void
        {
                
                ajout.id = idAjoutArray[i];
                btn_ajout.id = idBtnArray[i];
                
                btn_ajout.label = "-"+i;
                
                btn_ajout.addEventListener( MouseEvent.MOUSE_UP, moinsHandler );
                
        }
        private function moinsHandler( evt:MouseEvent ):void
        {
                i--;
                
                var s:String = evt.target.id;
                var j:int = int( s.charAt(9) );
                fi_mail_amis.removeChildAt( j );
                
        }
        private function plusHandler( evt:MouseEvent ):void
        {
                
                ajout = new MailAjoutHBox();
                ajout.id = "comp_ajout"+ i;
                fi_mail_amis.addChild( ajout );
                idAjoutArray.push( ajout.id );
                
                btn_ajout = new Button();
                btn_ajout.id = "btn_ajout" + i;
                btn_ajout.label = "+"+i;
                ajout.addChild( btn_ajout );
                idBtnArray.push( btn_ajout.id );
                
                minusAmisMail();
                i++;
        } 
        
        private function init():void
        {
                
                ajout = new MailAjoutHBox();
                ajout.id = "comp_ajout"+ i;
                fi_mail_amis.addChild( ajout );
                idAjoutArray.push( ajout.id );
                
                btn_ajout = new Button();
                btn_ajout.id = "btn_ajout" + i;
                btn_ajout.label = "+"+i;
                ajout.addChild( btn_ajout );
                idBtnArray.push( btn_ajout.id );
                
                btn_ajout.id = idBtnArray[i];
                if ( btn_ajout.id == "btn_ajout0" ) 
                btn_ajout.addEventListener( MouseEvent.MOUSE_UP, plusHandler );
                
                i++;
        }

Reply via email to