as child tag of an
<?xml version="1.0"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Panel title="My Application" paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10" width="300"> <mx:Script> private function addToCart():void { } </mx:Script> <mx:HBox width="100%"></mx:HBox> <mx:ControlBar width="100%"> <mx:Label text="Quantity" /> <mx:NumericStepper id="myNS" /> <mx:Spacer width="100%" /> <mx:Button label="Add to Cart" click="addToCart();" /> </mx:ControlBar> </mx:Panel> </mx:Application> Create controls with ActionScript and add to Panel <?xml version="1.0"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> import mx.containers.ControlBar; import mx.controls.*; import flash.events.MouseEvent; private var myCB:ControlBar=new ControlBar(); private var myLabel:Label=new Label(); private var myNS:NumericStepper=new NumericStepper(); private var mySpacer:Spacer=new Spacer(); private var myButton:Button=new Button(); private function addCBHandler():void { myLabel.text="Quantity"; mySpacer.percentWidth=100; myButton.label="New Button"; myButton.addEventListener('click', addToCart); myCB.percentWidth=100; myCB.addChild(myLabel); myCB.addChild(myNS); myCB.addChild(mySpacer); myCB.addChild(myButton); myPanel.addChildAt(myCB, myPanel.numChildren); myPanel.createComponentsFromDescriptors(); } private function addToCart(event:MouseEvent):void { Alert.show("Button clicked."); } </mx:Script> <mx:Panel id="myPanel" title="My Application" paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10" width="300"> <mx:HBox width="100%"></mx:HBox> <mx:Button label="Add ControlBar" click="addCBHandler();" /> </mx:Panel> </mx:Application>