PDA

View Full Version : ComboBox setting the first item selected problem


Ihou
01-18-2006, 11:03 AM
Well I have this problem from a long time and I could not manage to solve it. I have a mp3 streaming player wich songs are loaded from an xml file and are played from a ComboBox now. Before it was a List but i had to change it to a ComboBox. So the problem is that the first Item is always shown in the combobox but it cannot be played i have to select another one in the drop down list and after that If I select the first one it plays. What can I do to set the first Item as I have selected it. I have this script reffering to the combobox and also a lot more outside the movie clip where the combobox is.If somebody think that may help me I would send him the whole movie cause I am very desperate and trying to get this solved. :(
var songlist = new Array();
playlist.dataProvider = songlist;
//************************************************** ***
var songObj:XML = new XML();
songObj.ignoreWhite = true;
songObj.onLoad = function(check)
{
if(check)
{
trace("song loading ok!");
var baseNode2 = this.firstChild.childNodes;
var mylabel;
var mydata;
for (var j=0;j<baseNode2.length; j++)
{
if(baseNode2[j].nodeName == "Index")
{
mylabel = baseNode2[j].attributes.mylabel;
mydata = baseNode2[j].attributes.mydata;
songlist.addItem({label:mylabel,data:mydata});
}
}
}
else
{
trace("try again.")
}
}
_root.mysong_mc.songObj.load("songlist.xml");
//************************************************** ****
var path_var;
var index_var;
//************************************************** ***
var evtPlaylist = new Object();
evtPlaylist.change = function()
{
var path_var = playlist.selectedItem.data;
var index_var= playlist.selectedIndex;
_root.music = path_var;
_root.start_index = index_var;
_root.sending = path_var;
_root.removeone = playlist.selectedIndex;
trace(_root.music+_root.start_index);
_root.gotoAndPlay("start");
//_root.mySound.stop();
_root.songout = (playlist.selectedIndex+1) + "." + playlist.selectedItem.label;
_root.download = playlist.selectedItem.data;
}
playlist.addEventListener("change",evtPlaylist);

chrisxkelley
01-21-2006, 08:17 AM
i had this same problem. when you try to select the first item, if the xml hasnt loaded then it cant do it, so try this little snippet:


var selectFirst:Number = setInterval(
function():Void{
if (myList.selectedIndex != 0){
myList.selectedIndex = 0;
} else {
clearInterval(selectFirst);
}, 10
);


basically just tries to set the selected index at an interval, and when it finally does select, it'll stop trying.

hope that helps :]