PDA

View Full Version : [CS3] dynamic datagrid question


Kenwio
07-22-2008, 12:31 PM
Hello!

I want my datagrid named dataGrid to be populated dynamically at runtime.
I have an XML response (in PHP) that contains the names of fields in a MySQL table.
The XML-response looks like this:
<fields>
<field>
<fieldname>station_id</fieldname>
<fieldname>station_name</fieldname>
[etc]
</field>
<fields>

I've done this ActionScript code:


public var res:Array = new Array(request.lastResult.fields.field);
private function addDataGridColumns():void {
var i:int;
var dgc:DataGridColumn;
var cols:Array = dataGrid.columns;
for (i=0; i < res.length; i++) {
dgc = new DataGridColumn;
dgc.headerText = httprequest.lastResult.fields.field.fieldname;
//dgc.dataField =
cols.push(dgc);
dataGrid.columns = cols;
trace(cols);
}
}

When I run this I get the following error:
Error: Unknown Property: 'fieldname'.
....etc

any ideas?

Kenw

box86rowh
07-22-2008, 03:25 PM
at the top you bring your results into an array, first make sure that array is getting populated with the fields, then in your for loop use that array to get your headerText instead of referring to the httprequest.

Kenwio
07-22-2008, 06:47 PM
The thing is that this works:
public var res:Array = new Array(request.lastResult.fields.field);
...but this doesn't:
public var res:Array = new Array(request.lastResult.fields.field.fieldname);
This gives the following error:
Error: Unknown Property: 'fieldname'.
....etc

This is the XML:
<fields>
<field>
<fieldname>station_id</fieldname>
<fieldname>station_name</fieldname>
[etc]
</field>
<fields>
Any ideas to solve the Error: Unknown Property: 'fieldname'.?

Thanks in advance,
Kenw

Kenwio
07-23-2008, 08:29 AM
What am I'm doing wrong here?

How do you all fetch HTTP results to a variable in AS??

Kenw

box86rowh
07-23-2008, 06:07 PM
you can use a urlloader, and use the oncomplete event to read the data into an xml variable