3 Replies Latest reply on Oct 11, 2006 3:17 PM by Josh Johnson

    Creating Container Components

    Josh Johnson Level 1
      I'm guessing this is a simple question, but I'm not finding an answer anywhere.

      I'm trying to create a component that extends the VBox, such that whereever I specify this object, it'll display the contained objects in a vertical fashion, but I always want them proceeded by a common 'header object'. My question is this... how should the 'contained' objects be passed into the component? Do I need to create a special public variable for these items or what?

      As an example, if my component looked like this:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml" width="100%" height="100%">
      <mx:Label text="The Heading" />

      and my application included this:

      <mx:DataGrid id="foo" dataProvider ="{bar}" />

      How would I reference the DataGrid in the component that it knows to lay it out after the Label?
        • 1. Re: Creating Container Components
          Josh Johnson Level 1
          Anyone? Or is this just a really dumb question?
          • 2. Re: Creating Container Components
            ntsiii Level 3
            I know that in 1.5 it was not possible to create a component in mxml that had a static child and still be able to add dynamic children. The solution there was to implement the component using AS, and then dynamically, at run time, add the default children.

            I don't know if this has changed in 2.0.

            Does your component work at all?

            • 3. Re: Creating Container Components
              Josh Johnson Level 1
              So I think I got around the problem. Instead of trying to add the dynamic children to the component with static children, I turned it around and wrote a script that executes on creation complete to instantiate the static child, set it's properties and then add the child at the '0' position to the vbox's child list. That seems to work reasonably well. Here's the code to the GroupSet component..

              <?xml version="1.0" encoding="utf-8"?>
              <mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml"
              width="100%" height="100%" creationComplete="init()">
              import mx.containers.Panel;
              public var title:String;
              public var open:Boolean;
              private var groupPanel:GroupPanel;

              private function init():void {
              if (!open) {open = true};
              if (open == false) {this.height = 22};
              groupPanel = new GroupPanel();
              groupPanel.text = title;
              groupPanel.open = open;
              groupPanel.width = this.width;

              Now I have to add some event-based functionality to the component to set the 'open' state based on a trigger in the GroupPanel sub-component, and I'm good to go.