Forum Moderators: open

Message Too Old, No Replies

Pulling comboBox default from XML file

Need to set default index via XML

         

catcherintherye51

7:20 pm on Jul 19, 2006 (gmt 0)

10+ Year Member



I currently have a comboBox that is populated via an XML file. I have a FlashVars variable in my HTML that sets the comboBox.selectedIndex value, but I want to change it so that the selected combo box is set via the XML file.

Combo Box is populated with this:

var myData:XML = new XML ();
myData.ignoreWhite = true;
myData.load ("Data.xml");
myData.onLoad = function (success:Boolean):Void
{
if (success)
{
var data:XMLNode = this.firstChild;
var children:Array = data.childNodes;
var numItems:Number = children.length;

for (var i:Number = 0; i < numItems; i++)
{
var child:XMLNode = children[i];
var name:String = child.attributes.name;
var URL:String = child.attributes.URL;
comboBox.addItem (name,URL);
}
}comboBox.selectedIndex=default_indx //This value is set via HTML
}

Here's an example of what the XML looks like:

<villa name="Selection #3" URL="theurl.html" default_indx="2"/>

For some reason it reads the default_indx variable using FlashVars in the HTML, but it woun't read the default_indx variable through the XML file.

Any ideas?

Thanks!

alce

7:55 pm on Jul 19, 2006 (gmt 0)

10+ Year Member



If the default value is supposed to be static, you only need to assign it:

comboBox.selectedIndex=3;

The value of the fourth item in your XML will be displayed.

If the selected index needs to be set based on user input, you need to send the value trough the URL.

Did that help or did I misunderstood what you are trying to do?

catcherintherye51

8:07 pm on Jul 19, 2006 (gmt 0)

10+ Year Member



The selected value will be based on user input (via their combo box selection.) If the user selects the 4th item in a list, the user is directed to a new page that sets the default_indx to "3" via FlashVars within the HTML of the new page.

This method works, but instead of setting the default_indx in the HTML (which is hardcoded) I want to set the index through the XML file, which is still hard-coded but easier to adjust than separate HTML files. If I can set the default in the XML I can make the adjustments in the single XML file, rather than go to every HTML file and making the change.

Currently, if I want to add an item between 2 current items I'd need to adjust each of the HTML files and re-set their default_indx values. If I could do this in XML I can make the adjustments to the single XML file.

Make sense?

Thanks for your help! Please let me know if you have any other ideas.