3 Replies Latest reply on Feb 13, 2008 8:52 AM by ntsiii

    Question for Arraycollection

    mark416 Level 1

      I have a ArrayCollection acDept that saved the data passed from coldfusion cfc

      <cfquery name="getDepartment" datasource="bursary">
      SELECT DeptId, Dept FROM DeptList

      I want loop over all the ArrayCollection and show all the DeptId.I use the following code and I get error for "acDept.valueOf("DeptID")."

      for ( var i : int =0; i < acDept.length ; i++)

      Please help me to know which method I can use to get DeptID.Thanks

        • 1. Re: Question for Arraycollection
          Arty13 Level 1
          I dont believe the valueOf() function takes parameters.

          What I would do is...

          exmple code
          var myArray:Array = new Array();

          var item:Object = new Object();
          item.DeptID = 1;
          var item2:Object = new Object();
          item2.DeptID = 2;
          var item3:Object = new Object();
          item3.DeptID = 3;
          var item4:Object = new Object();
          item4.DeptID = 4;


          var myArrayCollection:ArrayCollection = new ArrayCollection(myArray);


          function displayID(item:*, index:int, arr:Array):void
          Alert.show(String(item.DeptID), "DeptID");


          When accessing values you want the data inside the ArrayCollection, not the ArrayCollection itself. That is why you are getting errors. So get ahold of the data inside the ArrayCollection and do your processing on that.

          Hope this helps you out.


          • 2. Re: Question for Arraycollection
            ntsiii Level 3
            If you have a string variable containing the name of the property yu want to access, you can use bracket notation, like this:
            var sPropertyName:String = "DeptID";
            Alert.show(acDept [ sPropertyName ] ); //assuming deptID is a string or number.
            (the extra spaces around the brackets are to keep this forum from misinterpreting them.)

            • 3. Re: Question for Arraycollection
              ntsiii Level 3
              And oops, as Art says, you need to do that with the individual collection elements, not the AC itself. Sorry for the too-quick response.