Groups | Blog | Home
all groups > coldfusion flash integration > february 2006 >

coldfusion flash integration : ComboBox Selected Flash Form



fs22
2/28/2006 9:48:09 PM
Greetings~

I wasn't sure where to post this question, so let me know if it needs to go
elsewhere.

I have a flash form that I am using remoting to pull data from a database. One
of the fields on the form is a cfselect/combobox. What I would like to do is
have the correct item in the combo box selected based upon the database
results. I am a newbie when it comes to AS, but have been using CF for years.
Here is the line in my AS on my form on which I am focusing...

state.selectedItem = results.getItemAt(0).state;

I also tried selectedIndex to no avail.

Any feedback would be appreciated.

Thanks,

Clay
GotJosh?
3/8/2006 8:27:18 PM
Hey there, this is pretty simple to do -- took me a bit though to figure it
out -- you need to see the attached code and find selectOption (which was
wrote by Asfusions group) the rest i wrote up to do other things, besides just
comboboxes, the others do grid selection based on results from db, list
(combobox with multi select enabled) based on db results, and retrieving a
users selection based on what they chose in the list.

This example also assumes you are using flash remoting... handling the result
in a respondHandler of some kind then you can use the selectOption()function to
handle the result and assign the selection to the combobox. enjoy it.


***how to call a function selectOption()*******

_root.selectOption(_root.somefieldname, results.item.need_status);
//may need to call root if its not declared in scope like in this example


***helper functions****


// helper function to select items in a dropdown
public function selectOption(select: mx.controls.ComboBox,
optionToSelect:String):Void{

//go through every record to find the right one
for (var i:Number = 0; i < select.length; i++) {
if (select.getItemAt([i]).data == optionToSelect){
select.selectedIndex = i;
break;
}
}
}
// helper function to select items in a dropdown
public function selectGridOption(select: mx.controls.DataGrid,
columnToSearch:String, optionToSelect:String):Void{

//go through every record to find the right one
for (var i:Number = 0; i < select.length; i++) {
if (select.getItemAt([i])[columnToSearch] == optionToSelect){
select.selectedIndex = i;
break;
}
}
}

// helper function to select items in a list
public function selectList(select: mx.controls.List, optionsToSelect:Array,
arrayLength:Number):Void{
// start first loop based on array length
var toSelect:Array = [];

for (var i:Number = 0; i < arrayLength; i++) {

//Next Loop is based on listbox index length - it has 8 indexes
//go through every record in listbox to
//find the right ones and select them

for (var z:Number = 0; z < select.length; z++) {
if (select.getItemAt([z]).data == optionsToSelect[i]){
toSelect.push(z);
}
}
}
select.selectedIndices = toSelect;
}

// helper function to get items selected in a list
public function listResults(select: mx.controls.List,
selectionMade:Array):Array {
// start first loop based on array length
var fromSelect:Array = [];
var x:Number;

for (var i:Number = 0; i < select.length; i++) {
for (var index:String in selectionMade){
if (selectionMade[index] == i){
x = select.getItemAt([i]).data;
fromSelect.push(x);
}
}
}
return fromSelect;
}
AddThis Social Bookmark Button