Further Adventures in Flash Forms - Pre-selecting Select Boxes

Posted on Aug 10, 2005

I will expand on the project as a whole further, but in building further on the Flash form I have been discussing recently, I needed to pre-select items in a cfselect box based upon the values returned by a remoting call. This was my solution (and I am certainly no ActionScript expert, so if someone has a better way please let me know).Basically, I am looping through the list and checking to see if the data matches the returned value. When it does, I set the selected item and break the loop:

for (var i:Number = 0;i < itemParent.length;i++) {
   if (itemParent.getItemAt(i).data == results.items[0].parentid) {
      itemParent.selectedIndex = i;
      break;
   }
}

Now, for a more complicated example. My query was returning a field that contained a list of IDs of items selected in a multiple select box. In this case, I first convert the list to an array in ActionScript. Then I create an empty array that will contain the indexes of the items on within my select box. Finally, the outer loop loops through the array of IDs and the inner loop loops over the values in select box. When I find a match, I append the index of the item to my array of indices and break the inner loop. When both loops are done, I set the selectedIndices property to the array of indices and I am done.

if (results.items[0].categories != "") {
   var categoryid_array:Array = results.items[0].categories.split(",");
   var categories_array = Array();
   for (var x:Number = 0;x < categoryid_array.length;x++) {
      for (var i:Number = 0;i < choosecategories.length;i++) {
         if (choosecategories.getItemAt(i).data == categoryid_array.getItemAt(x)) {
            categories_array.addItem(i);
            break;
         }
      }
   }
   choosecategories.selectedIndices = categories_array;
}

Somehow, this doesn't feel like the easiest way to do this. I am open to suggestions...anyone?

Related Entries:
Multiple selects related for Flash Forms - Selecting Multiple Elements
Populating a Flash Form from CFTree

Comments

Ray Did you ever find an elegant solution to this? The documentation on multiple selects is so bad -- this post was the first reference to "selectedIndices" I found!

-Ray

Posted By Ray / Posted on 12/10/2008 at 2:05 PM


Brian Rinaldi @Ray, sorry I did not. In fact, I haven't used Flash Forms in years. They are slow and hard to use in the end because they still rely on Flex 1.5. Plus, with Flex now cheap/free, there isn't need to use Flash Forms in my opinion.

Posted By Brian Rinaldi / Posted on 12/11/2008 at 4:46 AM


Ray Thanks Brian,

Yeah I don't actually like using Flash forms, but was working on something built by another developer and can't rebuild the whole thing.

Posted By Ray / Posted on 12/11/2008 at 8:23 AM


Write your comment



(it will not be displayed)





About

My name is Brian Rinaldi and I am the Web Community Manager for Flash Platform at Adobe. I am a regular blogger, speaker and author. I also founded RIA Unleashed conference in Boston. The views expressed on this site are my own & not those of my employer.