Use addChildAt() to add the CheckBox control to VBox
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
import mx.controls.CheckBox;
import mx.controls.Alert;
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.addChildAt(myCheckBox, 0);
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>
Related examples in the same category