1 Reply Latest reply on Dec 19, 2006 5:01 AM by flexstudy

    loading controls dynamically at runtime in response to an event

    venkat1978
      I need to dynamically load user interface controls at runtime. These controls should appear on, say, a panel or other container in response to a mouse or keyboard event. What classes or api do we have to use for this?

      Thanks in advance
        • 1. Re: loading controls dynamically at runtime in response to an event
          flexstudy
          Create new mxml component

          ColorCheckbox.mxml
          --------
          <?xml version="1.0" encoding="utf-8"?>
          <mx:CheckBox styleName="glass" xmlns:mx=" http://www.adobe.com/2006/mxml">

          </mx:CheckBox>
          ---------
          Call function createColorCheckBoxes() on clicking any component

          public function createColorCheckBoxes():void {
          var colorCheckBox:ColorCheckBox;
          var gridRow:GridRow;
          var gridItem:GridItem;

          colorCheckBox=new ColorCheckBox();
          colorCheckBox.id="red"
          colorCheckBox.label="Red";

          colorCheckBox.addEventListener(MouseEvent.CLICK, clickCheckBox, false, 0, true);

          gridItem =new GridItem();
          gridItem.percentWidth=100;
          gridItem.percentHeight=100;
          gridItem.addChild(colorCheckBox);
          gridRow.addChild(gridItem);
          colorGrid.addChild(gridRow);
          colorGrid.validateNow();
          }

          Here I have

          <mx:Grid id="colorGrid" >
          </mx:Grid>

          private function clickCheckBox(event:MouseEvent):void {
          Alert.show("Clicked");
          }
          regards,
          Deshpande