This code does not look right to me:

for (var r:int; r < columns.length; r++)
{
     row += [columns[r] = data[i][r]];
}

Given that I don't know how your data/columns are laid out, I have put
together a small example that may or may not help. I am sorry if my
assumptions are incorrect. Here is my stab in the dark as to what you
are trying to achieve:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
layout="absolute">
     <mx:Script>
         <![CDATA[
             import mx.collections.ArrayCollection;

             private var columnsArray:Array = ["name", "address",
"phone", "email"];
             private var dataArray:Array = [
                 "Jon Doe", "87 US Street", "555-0125", "[email protected]",
                 "Jane Doe", "1250 Dixie Drive", "555-8752",
"[email protected]",
                 "Steve Smith", "5215 Jones Lane", "555-9853",
"[email protected]"
                 ];

             private var columnsAC:ArrayCollection = new
ArrayCollection(columnsArray);
             private var dataAC:ArrayCollection = new
ArrayCollection(dataArray);

             private function doConvert():void
             {
                 var convertedAC:ArrayCollection = convert(columnsAC,
dataAC);
             }

             private function convert(columnsAC:ArrayCollection,
dataAC:ArrayCollection):ArrayCollection
             {
                 var returnArray:Array = new Array();
                 var numColumns:uint = columnsAC.length;
                 for(var i:uint = 0 ; i < dataAC.length/numColumns ; i++)
                 {
                     var row:Object = new Object();
                     for(var j:uint = 0 ; j < columnsAC.length ; j++)
                     {
                         row[columnsAC[j]] = dataAC[i * numColumns + j];
                     }
                     returnArray.push(row);
                 }
                 return new ArrayCollection(returnArray);
             }
         ]]>
     </mx:Script>
     <mx:Button label="Convert" click="doConvert()"/>
</mx:Application>



HTH



Steve

--- In [email protected], "Wally Kolcz" <wko...@...> wrote:
>
> I have been working on trying to convert the Web Service result from
> Blue Dragon to a usable, bindable ArrayCollection for a while now. I
> think I have come up with a solution for a function that will do it
for
> me, but I just can't get it right. Maybe someone could help. I am
> returning the data from the Web Service as Objects (returnformat) and
> have been able to attach them to a datagrid by using their index
> numbers.
>
> I attached 2 images to this email. One of the returned
> ArrayCollection of column names (columnList) and the other of the
> values (data). I want to create an ArrayCollection that has the column
> names matched with their values for each record row returned.
>
> Here is the function I have so far:
>
>         public function convert(total:int, columns:ArrayCollection,
data:ArrayCollection):ArrayCollection {
>
>             var AC:ArrayCollection = new ArrayCollection();
>
>             for(var i:int = 0; i < total; i++) {
>
>                 var row:Object = new Object();
>
>                 for (var r:int; r < columns.length; r++) {
>                     row += [columns[r] = data[i][r]];
>                 }
>                 AC.addItem(row);
>             }
>             return AC;
>         }
>
> total is the length of the event.result which is being passed in.
columns is the ArrayCollection (e.result.columnList) and data is the
ArrayCollection (e.result.data);
>

Reply via email to