--- In [email protected], "ew6014" <ew6...@...> wrote:
>
> hi guys. i was reading flex3 for dummies page 221 on containers and it gave 
> an example of adding childen using actionscript. it worked fine. but i 
> thought about adding a removeChild function. but it doesnt seem to be 
> working. can someone tell me why?
> 
> i apologize if this is a stupid mistake.
> 
> ---------------------------------------------
> <?xml version='1.0' encoding='utf-8'?>
> <mx:Application xmlns:mx='http://www.adobe.com/2006/mxml' layout='vertical'>
> <mx:Script>
>       <![CDATA[
>               
>       import mx.controls.CheckBox;
>       private function addCheckBox():void 
>       {
>       var checkBox:CheckBox = new CheckBox();
>       checkBox.label = "Checkbox " + (myVBox.numChildren + 1);
>       myVBox.addChild(checkBox);
>       }
> 
>       private function removeCheckBox():void 
>       {
>       var checkBox1:CheckBox = new CheckBox();
>       checkBox1.label = "Checkbox " + (myVBox.numChildren - 1);
>       myVBox.removeChild(checkBox1);
>       }
>       ]]>
> </mx:Script>
> <mx:Button label='Add Checkbox' click='addCheckBox()' />
> <mx:Button label='Remove Checkbox' click='removeCheckBox()' />
> 
> <mx:VBox id='myVBox' />
> </mx:Application>

You're removing a new child you created and never added, not one that already 
existed.  Consider using a repeater to handle this for you.

HTH;

Amy


Reply via email to