Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 07-22-2008, 12:31 PM   #1
Kenwio
Registered User
 
Join Date: Jul 2008
Posts: 48
Talking [CS3] dynamic datagrid question

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:
Code:
<fields>
 <field>
  <fieldname>station_id</fieldname>
  <fieldname>station_name</fieldname>
  [etc]
 </field>
<fields>
I've done this ActionScript code:

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:
Quote:
Error: Unknown Property: 'fieldname'.
....etc
any ideas?

Kenw

Last edited by Kenwio; 07-22-2008 at 12:48 PM.
Kenwio is offline   Reply With Quote
Old 07-22-2008, 03:25 PM   #2
box86rowh
FLEX AND FLASH ARE COOL
 
Join Date: Oct 2005
Posts: 794
Default

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.
box86rowh is offline   Reply With Quote
Old 07-22-2008, 06:47 PM   #3
Kenwio
Registered User
 
Join Date: Jul 2008
Posts: 48
Default

The thing is that this works:
ActionScript Code:
public var res:Array = new Array(request.lastResult.fields.field);
...but this doesn't:
ActionScript Code:
public var res:Array = new Array(request.lastResult.fields.field.fieldname);
This gives the following error:
Code:
Error: Unknown Property: 'fieldname'.
....etc
This is the XML:
Quote:
<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 is offline   Reply With Quote
Old 07-23-2008, 08:29 AM   #4
Kenwio
Registered User
 
Join Date: Jul 2008
Posts: 48
Default What am I'm doing wrong here?

What am I'm doing wrong here?

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

Kenw
Kenwio is offline   Reply With Quote
Old 07-23-2008, 06:07 PM   #5
box86rowh
FLEX AND FLASH ARE COOL
 
Join Date: Oct 2005
Posts: 794
Default

you can use a urlloader, and use the oncomplete event to read the data into an xml variable
box86rowh is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic text question RaymondP ActionScript 2.0 6 07-07-2007 06:57 PM
xml and dynamic text box question Zaphod ActionScript 1.0 (and below) 3 04-05-2007 11:05 AM
Dynamic Text question mrras25 ActionScript 2.0 9 03-06-2007 09:55 PM
DataGrid Content Question Lienne ActionScript 2.0 9 08-05-2005 09:24 PM
dynamic variables (newbie question) smirnie Simple Stuff (Newbies) 13 05-07-2004 07:46 AM


All times are GMT. The time now is 08:16 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.