2 Replies Latest reply on Jun 15, 2008 12:30 PM by shahkumar

    Loop through query records to display text information

    shahkumar
      I am just starting on Flex 3, and building a sample site right now. I have it setup that ny News section is divided between two company names, accordion navigation.

      [CODE]
      <mx:Canvas label="About Us" width="100%" height="100%">

      <mx:Accordion id="companies" x="43" y="42" width="70%" height="70%">

      <mx:Canvas id="km" width="100%" height="100%" label="Kumar Motors" creationComplete="getCompanyNews(2,km.id);">

      </mx:Canvas>

      <mx:Canvas id="ka" width="100%" height="100%" label="Kumar Automobiles" creationComplete="getCompanyNews(1,ka.id);">

      </mx:Canvas>

      </mx:Accordion>


      </mx:Canvas>
      [/CODE]

      When the getCompanynews function is called, it makes a call to the coldfusion CFC that returns a query which goes to the event handler.

      getCompanyNewsCode:
      [AS]public function getCompanyNews(companyID:int,canvasID:String):void{
      var arrCompanyID:Array = new Array();
      arrCompanyID[0] = companyID;
      cfdata.getCompanyNews(arrCompanyID);

      }[/AS]

      Event Handler Code:
      [AS]public function CompanyNewsEventHandler(companyNewsEvent:ResultEvent):void{
      arrCompanyNews = companyNewsEvent.result as ArrayCollection;
      companyNewsCanvas = new Canvas();
      var arrNews:Array = new Array();
      for(var i:int=0; i<arrCompanyNews.length;i++)
      {
      var lbl:Label = new Label();
      lbl.id = arrCompanyNews[0].CompanyNews_ID;
      lbl.text = arrCompanyNews[0].CompanyNewsItem;
      companyNewsCanvas.addChild(lbl);
      }
      if(arrCompanyNews[0].Company_ID == 2)
      {
      km.addChild(companyNewsCanvas);
      }else{
      ka.addChild(companyNewsCanvas);
      }

      }[/AS]

      The issue I have is that the labels I am adding get overwritten. How do I create dynamic label names or how do I add the news item to the canvas for display?

      Also, as you notice, I have to use if/else to figure out which compass creation caused the call event, anyway to do that dynamically?

      Thanks a lot