|
|
Question : In Flash Populate a Combo box Component with data from a MySQL database
|
|
Hi,
I am using Flash. How do I Populate a Combo box component with data from a database. I am not using XML. But I am using PHP+MySQL. Please let me know about the same.
Thanks,
VP
|
Answer : In Flash Populate a Combo box Component with data from a MySQL database
|
|
you can use LoadVars() or Remoting with AMFPHP
I would recommend using remoting if you have a lot of data that also will be pulled from a database... otherwise just use LoadVars().
like this...
var myLV:LoadVars = new LoadVars(); myLV.onLoad = function(success){ if(success){ var labelsArray:Array = new Array(); var dataArray:Array = new Array(); for(var i:String in myLV){ if(i.indexOf("label")) labelsArray.push(i); if(i.indexOf("data")) dataArray.push(i); } for(var j:Number = 0; j < labelsArray.length; j++) { myCB.addItem( {label: labelsArray[j], data: dataArray[j]} ); } } };
myLV.load("data.php", myLV, "POST");
this assumes you have a comboBox on the same frame as the above code and you have given it an instance name of myCB.
it also assumes that your data is setup in PHP to be in the below sequence...
label1=About&data1=1&label2=Services&data2=2&label3=Contact Us&data3=3&
so using label and data with number after then... the combo box will place then in a reverse order, so either format the array inside of flash or in your PHP code.
rp
|
|
|
|
|