Hello
I seem to keep getting a problem to fill a combo box in flash CS3 (actionscript 2.0)
I made a php file wich reads data from a mysql table and then puts it in an array (this works fine. I seperated it to data and label(name) and afterwards exported it to read it in flash as data and label. But when I read it in flash nothing happens, I keep getting ‘undefined’…
Here’s my code:
Combolist.php:
<?
//connect to database
mysql_connect(“localhost”,“username”,“passwoord”) or die (“didn’t connect to mysql” . mysql_error());
mysql_select_db(“combolistinfo”) or die (“no database” . mysql_error());
//make query
$query = “SELECT list FROM combo”;
$result = mysql_query( $query ) or die (“didn’t query” . mysql_error());
$num = mysql_num_rows( $result );
$ComboName = array();
$ComboData = array();
$j = 0;
while ($row = mysql_fetch_row($result)){
$ComboName[$j] =$row[0];
$ComboData[$j] =$row[0];
$data[] = $ComboName[$j].":".$ComboData[$j];
$j++;
}
print implode("
",$data);
mysql_close($DBConn);
?>
so this above works properly!!
flash fill combolist.fla:
tmp=new Array();
tmp2=new Array();
//make new loadvar
myDataCombo = new LoadVars();
//load php file
myDataCombo.load(“Combolist.php”);
//get data from php file
myDataCombo.onData = function(raw) {
//split data to fill array
tmp = raw.split("
");
for (var i = 0; i<tmp.length; i++) {
tmp2 = tmp*.split(":");
_root.cmblist.addItem(tmp2[0],tmp2[1]);
}
};
//execute function
traceCombo();
//function to read data and label that is selected
function traceCombo(com) {
trace("Selected Data: "+com.getSelectedItem().data);
trace(“Selected Label: “+com.getSelectedItem().label);
trace(”--------------------------------------”);
}
I tried it a couple of times with other possiblities, but it didn’t work. Please help me on this!
Thanks already!