6 Replies Latest reply on Nov 30, 2009 2:29 AM by PiyushChitkara

    addChild Not working in a loop with custom component

    PiyushChitkara Level 1

      Hi,

       

      I have a custom component 'form component'

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Form xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%">
          <mx:Script>
              <![CDATA[
                  import mx.controls.Alert;
                  import flash.net.navigateToURL;
                 
                  public var documentName:String;
                  public var documentLocation:String;
                  public var documentDescription:String;
                  public var documentLevel:String;
                 
             
                  private function openLink():void
                  {
                      var urlRequest:URLRequest=new URLRequest(documentLocation);
                      navigateToURL(urlRequest,"_blank");
                  }
                 
              ]]>
          </mx:Script>
          <mx:FormItem width="100%" height="100%" paddingRight="10" borderThickness="10">
              <mx:VBox width="100%" cornerRadius="10" borderThickness="2" borderStyle="solid" borderColor="#D5D2D2">
                  <mx:ApplicationControlBar width="100%"  fillAlphas="[1.0, 0.52]" fillColors="[#FFFFFF, #B3CDD9]">
                      <mx:LinkButton id="eachDocumentName" label="Name" click="openLink()" textAlign="left" width="50%" />
                      <mx:Label id="eachDocumentLevel" text="Level" textAlign="right" width="50%"/>
                  </mx:ApplicationControlBar>

                  <mx:Label id="eachDocumentDescription" width="100%" text="Description" paddingTop="5"  paddingLeft="10"/>
                  <mx:Label height="10" width="100%" />
              </mx:VBox>
             
          </mx:FormItem>
      </mx:Form>

       

      and I Want to add this component inside a VBox for a loop dynamically like

      Script Code:

      private function showDocuments(event:ResultEvent):void
                  {
                      var documentList:ArrayCollection=event.result.root.documents.document;
                     

                      for(var i:int=0;i<documentList.length;i++)
                      {
                         
                         
                          var documentName:String=documentList[i].name.toString();
                          var documentDescription:String=documentList[i].description.toString();
                          var documentLevel:String=documentList[i].level.toString();
                          var documentLocation:String=documentList[i].location.toString();
                         
                          
                          createChildForFilePanel(documentName,documentLevel,documentDescription,documentLocation);
                         
                      }
                     
                     
                     
                  }
                 
                  private function createChildForFilePanel(documentName:String,documentLevel:String,documentDescription:Stri ng,documentLocation:String):void
                  {
                         
                          Alert.show("function Called");
                          var documentListing:DocumentListing=new DocumentListing();
                         
                         
                          documentListing.percentWidth=100;
                          documentListing.percentHeight=100;
                          documentListing.eachDocumentName.label=documentName;
                          documentListing.eachDocumentLevel.text=documentLevel;
                          documentListing.eachDocumentDescription.text=documentDescription;
                          documentListing.documentLocation=documentLocation;
                           
                          filePanel.addChild(documentListing);
                  }

       

       

      MX: code

        <mx:VBox id="filePanel" label="File Content" width="100%" height="100%" borderThickness="0" >
                     
                         
            </mx:VBox>

       

       

      This is actually Not working.. Am I doing anything wrong. I have included the component in the namespace..

       

      Thanks In Advance,

      Piyush