Creating and removing a child of an VBox container
<?xml version="1.0"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> import mx.controls.CheckBox; private var myCheckBox:CheckBox; private var checkBoxDisplayed:Boolean = false; public function addControlButton():void { if(checkBoxDisplayed==false){ if (!myCheckBox) { myCheckBox = new CheckBox(); } myCheckBox.label = "New CheckBox"; myVBox.addChild(myCheckBox); checkBoxDisplayed=true; } } public function deleteControlButton():void { if(checkBoxDisplayed){ myVBox.removeChild(myCheckBox); checkBoxDisplayed=false; } } </mx:Script> <mx:VBox id="myVBox"> <mx:Button label="Add CheckBox" click="addControlButton();" /> <mx:Button label="Remove CheckBox" click="deleteControlButton();" /> </mx:VBox> </mx:Application>