I didn't test your code, but I think the problem comes from the way you
index your controls and how you use this index to remove them.
You use the index "i", which should reflect the number of created controls,
in their names. Then use the name to get the index back and use the
index with "removeChildAt".
Let's simulate this:

1. We add 4 controls: btn_ajout0, btn_ajout1, btn_ajout2, btn_ajout3 and i=4
2. Remove one in the middle (say btn_ajout1): btn_ajout0, btn_ajout2,
btn_ajout3 and i=3
3. Now you are in an inconsistent state: btn_ajout0 (child 0), btn_ajout2
(child 1), btn_ajout3 (child 2)
4. If you try to remove btn_ajout2 you wil actually remove btn_ajout3 and if
you try to remove btn_ajout3 you will get the index out of bounds error!

Another possible bug: What if you have more than 10 controls? s.charAt(9)
won't work anymore!

Hope this helps!


On Sun, Oct 5, 2008 at 7:05 PM, quantum_ohm <[EMAIL PROTECTED]>wrote:

>   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++;
> }
>
>  
>



-- 
Haykel Ben Jemia

Allmas
Web & RIA Development
http://www.allmas-tn.com

Reply via email to