all groups > flash (macromedia) > may 2005 >
You're in the

flash (macromedia)

group:

Pb with comboboxes


Pb with comboboxes ritpas
5/30/2005 8:38:51 PM
flash (macromedia):
Hi,

I have problem with combobox.

The data are properly retrieved, all the item are present in the list, but the
first item is always blank (the default value displayed in the list).

//com is an array containing the data to put in the list
communes.dataProvider = com;
communes.sortItemsBy("label", "ASC");
com.addItemAt(0, "TOUTES");

In fact, I want the "TOUTE" value to be displayed as default value therefore I
used :

communes.selectedIndex=0;

but it doesn't work. The list still shows a blank undefined default value!!!??

By the way, could anybody explain me why I had to use :
com.addItemAt(0, "TOUTES");
instead of
communes.addItemAt(0, "TOUTES");
the latter didn't work though the manual states that the instance should be
used with the addItemAt method (here I used the array which provided the data
and it works but I don't understand!! Strange)

Your help will be greatly appreciated
Re: Pb with comboboxes auk9
6/13/2005 12:00:00 AM
ritpas - your code actually worked for me. Here is what I did.

1) made a new flash doc
2) dragged a combobox into it and named it "communes"
3) put the following code into the first frame:

import mx.controls.ComboBox;
var communes:ComboBox;
var com:Array = new Array();
com[0] = {label:"a"};
com[1] = {label:"b"};
communes.dataProvider = com;
communes.sortItemsBy("label", "ASC");
com.addItemAt(0, "TOUTES");
communes.selectedIndex = 0;

When I ran this, it worked. One thing you can try if this doesn't work for you
is to replace the line:
com.addItemAt(0, "TOUTES");
with:
com.addItemAt(0, {label:"TOUTES"});

to add it as an object with a label property instead of a string.

-good luck

AddThis Social Bookmark Button