as child tag of an : Panel ControlBar « Container « Flex






as child tag of an

<mx:ControlBar> as child tag of an <mx:Panel>
            
<?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>

   
    
    
    
    
    
    
    
    
    
    
    
  








Related examples in the same category

1.ControlBar for a PanelControlBar for a Panel
2.Panel.controlBarContent defines the controls that appear in the control bar areaPanel.controlBarContent defines the controls that appear in the control bar area
3.ControlBar for PanelControlBar for Panel
4.Specify tag as the last child tag of an tagSpecify <mx:ControlBar> tag as the last child tag of an <mx:Panel> tag
5.Add ControlBar container dynamically to a Panel containerAdd ControlBar container dynamically to a Panel container