You are not removing one of the checkboxes you added. If you check the
documentation for VBox at
http://livedocs.adobe.com/flex/3/langref/mx/containers/VBox.html you will see
there are a couple of ways to remove a single child - removeChild and
removeChildAt.
removeChild would work if you had kept a reference to the child that was added.
Seeing as how you created each checkbox dynamically, you will need to use
removeChildAt. So, first thing we need to know - how many children in our
vBox...
var vBoxKids:Array = myVBox.getChildren();
var numKids:int = vBoxKids.length;
Now we can remove the last one...
if(myVBox.getChildAt(numKids - 1) is CheckBox)
{
myVBox.removeChildAt(numKids - 1);
}
HTH
Steve
--- 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>
>