Add controls to ControlBar : ControlBar « Components « Flex






Add controls to ControlBar

         
<?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>

   
    
    
    
    
    
    
    
    
  








Related examples in the same category

1.Creating a ControlBar containerCreating a ControlBar container
2.Controlbar with vertical ruleControlbar with vertical rule
3.A ControlBar with a Spacer