1 Reply Latest reply on Nov 3, 2006 3:20 PM by mrbahr

    problem in creating a custom component based on another custom component

    overtime66
      Hi,
      Im using flex builder 2 with action script 3.0.
      I have created a custom mxml component named MvPortlet.
      When i'm trying to create a new mxml component based on MvPortlet i receive the following error:

      "Multiple sets of visual children have been specified for this component (base component definition and derived component definition)".

      However,when i create a new actionscript class, extend MvPortlet and add some visual components the error is not generated.

      Any ideas????

      thanks,

      Joseph G
        • 1. Re: problem in creating a custom component based on another custom component
          mrbahr
          This is not the most intuitive thing in the world, but this works:

          Let's say that this is your base component called CustomBase:

          <mx:Panel .....>
          private var _content:Array;
          public function set content(content:Array):void {
          _content = content;
          }

          public function addComponents():void {
          this.removeAllChildren();
          for each (var component:DIsplayObject in _content)
          this.addChild(component);
          }
          </mx:Panel>

          Your extended component could be something like:

          <custom:CustomBase xmlns:custom="com.yourpackage.custom.*" ....
          creationComplete="initme();">
          <mx:Script>
          ....
          private function initme() {
          this.addComponents();
          }
          </mx:Script>
          <custom:content>
          ....
          put all your components here
          </custom:content>
          </custom:CustomBase>

          So, what this does is create an array of components that you have the parent
          display in the appropriate container. The <custom:content> element takes the child elements and puts them into the array of display objects. The creationComplete method then calls the base component's addComponents method that then inserts the array items into the target container.

          Hope this helps.

          Tom