PDA

View Full Version : Dynamic DataGrid gives TypeError: Error #1009


Kenwio
07-21-2008, 11:42 AM
Hi!

What I'm basically trying to do is to create an array that contains all the column name that a table in a MySQL database conists of. I've done the PHP script that successfully gets the name of each column in the specified table, and outputs the data in an XML format to the HTTPService..

$query = mysql_query('SELECT * FROM stations');
$return = "<fields>";
$numberfields = mysql_num_fields($query);

for ($i=0; $i<$numberfields ; $i++ ) {
$var = mysql_field_name($query, $i);
$return .= "<field><fieldname>".$var."</fieldname></field>";
}
$return .= "</fields>";
echo $return;

Now, what I need to do is to add new DataGrid columns to a DataGrid depending on the number of objects(column names) that's being returned from the PHP file. I've done a function called addDataGridColumn and tried this code:

private function addDataGridColumn():void {
var httpServ:HTTPService = new HTTPService();
httpServ.url = "http://localhost/re.php";
httpServ.useProxy = false;
httpServ.method = "POST";
var columnArr:Array = new Array(httpServ.lastResult.fields.field.fieldname);
var i:int;
var dgc:DataGridColumn;
var cols:Array = dataGrid.columns;
for (i=0; i < columnArr.length; i++) {
dgc = new DataGridColumn(httpServ.lastResult.fields.field.fi eldname);
cols.push(dgc);
dataGrid.columns = cols;
}
}



...but when I run it, I get an error that refers to the
var columnArr:Array = new Array(httpServ.lastResult.fields.field.fieldname);
line:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at reportMain3/addDataGridColumn()[C:\wampserver'v1.7.4\www\FlashDevelopProjekt\TestP roject\src\reportMain3.mxml:53]
at reportMain3/___reportMain3_Application1_applicationComplete()[C:\wampserver'v1.7.4\www\FlashDevelopProjekt\TestP roject\src\reportMain3.mxml:7]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\ core\UIComponent.as:9051]
at mx.managers::SystemManager/preloader_preloaderDoneHandler()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\ managers\SystemManager.as:2251]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.preloaders::Preloader/displayClassCompleteHandler()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\ preloaders\Preloader.as:434]
at flash.events::EventDispatcher/dispatchEventFunction()

Any ideas for a solution?:confused:

ActionScript v3.0
WAMP5 v1.7.4
FlashDevelop v3.0.0.7


Best Regards,
Kenwio

Kenwio
07-21-2008, 08:29 PM
What?? Noone knows?:o