1 Reply Latest reply on Aug 18, 2006 2:59 PM by frickin_chicken

    Updating size after addChild

    reFlexive
      I'm creating a dynamic UI using addChild. After I've added all of the children, I get a grid of labels and fields.

      I have verticalScrollPolicy set to "auto" for the container, but it doesn't automatically update after I've finished adding the children. I've tried invalidating the component and its parent, but that still doesn't seem to update the height (sometimes I can get the scrollbar to show up if I directly set the height of the component, but the height is never quite right).

      Does anyone know a trick for updating the height of a component after children have been added with addChild?

      Here's the main method I'm using to populate child components:

      public function initDisplay():void {

      if (null != dataProvider) {

      // A field contains the code, any linkedCode, and a value
      var field:XML;
      var code:String;
      var linkedCode:String;
      var value:String;

      var gridRow:GridRow;
      var gridItem:GridItem;
      var label:Label;
      var inputField:TextInput;

      var i:int;
      var grid:Grid = new Grid();
      grid = Grid(addChild(grid));

      for (i = 0; i < dataProvider.length(); i++) {
      // Get the data values
      field = XML(dataProvider );
      code = field.code.toString();
      linkedCode = field.linkedCode.toString();
      value = field.value.toString();

      // Create the UI widgets
      gridRow = new GridRow();
      gridRow = GridRow(grid.addChild(gridRow));

      gridItem = new GridItem();
      label = new Label();
      label.text = FACResources.getFeatureAccessCodeDisplay(code);
      label = Label(gridItem.addChild(label));
      gridItem = GridItem(gridRow.addChild(gridItem));

      gridItem = new GridItem();
      inputField = new TextInput();
      inputField.id = code;
      inputField.text = value;
      inputField.width = 65;
      inputField = TextInput(gridItem.addChild(inputField));
      gridItem = GridItem(gridRow.addChild(gridItem));

      //rowHeight = gridRow.getExplicitOrMeasuredHeight();
      rows++;

      fieldMap[code] = inputField;
      }

      //(UIComponent(parent)).invalidateSize();
      //(UIComponent(parent)).validateSize();


      //this.verticalScrollBar.invalidateSize();
      //updateSize();
      }
      }

      Thanks.
        • 1. Re: Updating size after addChild
          frickin_chicken
          after you add the gridrow, does its height property get populated properly? if so then you can just sum them and set the grid's height at the end of your loop.

          im not totally sure i get what youre doing. maybe you are looking for something slicker. i know for a datagrid there is a method for measuring the total height based on its chillins.

          im new here.