You are trying to remove a child that has never been added. In your
addCheckBox function you are creating a new CheckBox and then adding it
which is fine but then in your removeCheckBox function you are again
creating a brand new CheckBox and trying to remove it. This will not work
because the new CheckBox in removeCheckBox has never been added. What you
need to do is reference the CheckBox that you created in yoru addCheckBox
function. You could do this by moving the checkBox var outside of the
functions and just make it a public var. Or when you create the CheckBox you
could set it's name property in addCheckBox and then in your removeCheckBox
do myVBox.removeChild)myVBox.removeChild.getChildByName("whatevername"));

On Mon, Jun 29, 2009 at 5:30 AM, ew6014 <ew6...@yahoo.com> 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>
>
>  
>

Reply via email to