Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comboboxes and XML

Status
Not open for further replies.

malpeigne

Technical User
Jul 27, 2004
7
US
Hello. I'm creating an interactive map. The base map (first scene, first frame) has only building outlines and streets. Above the map are several drop down lists (using comboboxes). If the user selects an item in the combobox, the corresponding building is highlighted and labeled. So far I've accomplished this by creating a different scene for each building, different from the base in that it also includes the highlight and label. I'm keeping the building information in an XML file so it can be easily updated:

<?xml version="1.0" standalone="yes"?>
<buildings>
<site siteName="Building01" Data="B1"></site>
<site siteName="Building02" Data="B2"></site>
<site siteName="Building03" Data="B3"></site>
</buildings>

My actionscript to link the comboboxes with the XML files is:

//create a new XML object
thisXML = new XML();
//ignore whitespace in the file
thisXML.ignoreWhite = true;
//call the LoadChartData function when the XML file is loaded
thisXML.onLoad = LoadCombo;
//load the xml file
thisXML.load("buildings.xml");

function LoadCombo(success) {

if (success) {
//set variables
var BaseNode=thisXML.childNodes[0];
var ComboSites = new Array();
var ComboData = new Array();
var ThisNode;

//set .dataprovider "not needed but nice to have"
CBOLoadBuildings.setDataProvider(ComboSites);
//add the default item to the combo box
CBOLoadBuildings.addItem("--Buildings--");

//get building information
for (i=0; i < BaseNode.childNodes.length; i++) {
ThisNode = BaseNode.childNodes;
ComboSites = ThisNode.attributes["siteName"];
ComboData = ThisNode.attributes["Data"];
//add to combo box
CBOLoadBuildings.addItem(ComboSites,ComboData);
}
}
}

//Function Call for navigation and to restore comboBoxes
CBOLoadbuildings.setchangeHandler("navigateBuildings");


//functions
function navigateBuildings() {
if (CBOLoadBuildings.getSelectedItem().data != null){//stops recursion by checking for valid selection
CBOLoadAcademic.setSelectedIndex(0);
CBOLoadAdmin.setSelectedIndex(0);
CBOLoadResidence.setSelectedIndex(0);
CBOLoadCamp.setSelectedIndex(0);
_root.gotoAndPlay(CBOLoadBuildings.getSelectedItem().data);
}
}
stop();


I have several questions:

1. The menus are not working. Nothing happens when an item is selected. Any idea why?

2. Do you know a better way to accomplish what I am trying to do?

3. I want the menus to reset once an item is selected. So if I select "Building01" I want the menu to automatically reset to show "--Buildings--". Do you know how to do this?

Thanks for any help you can provide,
malpeigne
 
What version of Flash are you using?

Wow JT that almost looked like you knew what you were doing!
 
Hi pixl8r,

Thanks for such a quick reply. I am using Flash MX 2004.

--malpeigne
 
Try this:

Code:
//create a new XML object
thisXML = new XML();
//ignore whitespace in the file
thisXML.ignoreWhite = true;
//call the LoadChartData function when the XML file is loaded
thisXML.onLoad = LoadCombo;
//load the xml file
thisXML.load("buildings.xml");

function LoadCombo(success) {
    
 if (success) {
        //set variables
        var BaseNode=thisXML.childNodes[0];
        var ComboSites = new Array();
        var ComboData = new Array();
        var ThisNode;
        
        //set .dataprovider "not needed but nice to have"
        CBOLoadBuildings.setDataProvider = ComboSites;
        //add the default item to the combo box
        CBOLoadBuildings.addItem("--Buildings--");
        
        //get building information
        for (i=0; i < BaseNode.childNodes.length; i++) {
            ThisNode = BaseNode.childNodes[i];
            ComboSites[i] = ThisNode.attributes["siteName"];
            ComboData[i] = ThisNode.attributes["Data"];
        //add to combo box
        CBOLoadBuildings.addItem(ComboSites[i],ComboData[i]);
        }
    }
}

myComboListener = new Object();
myComboListener.change = function(component){
	//removed if statement.  If the function fires there is definitely data.
	trace(component.target.value);//remove after testing
	itemSelected = component.target.value;
	trace("itemSelected="+itemSelected);//remove after testing
	_root.gotoAndPlay(""+itemSelected+""); //assuming target is a frame label
	CBOLoadAcademic.selectedIndex = 0;
	CBOLoadAdmin.selectedIndex = 0;
	CBOLoadResidence.selectedIndex = 0;
	CBOLoadCamp.selectedIndex = 0;
	CBOLoadBuildings.selectedIndex = 0;

}

CBOLoadBuildings.addEventListener("change",myComboListener);

To answer your questions:

1) Have a look at the listener object and note the differences. Also take a look at the change to the dataProvider line.

2) Yes. :)

3) Note the replacement for "setSelectedIndex" in the myComboListener Object.

Hope it helps!

Wow JT that almost looked like you knew what you were doing!
 
Hi pixl8r,

This is still not working for me. I have a few questions to make sure I am implementing the script correctly:

1. I have 5 comboboxes on my map (different categories for buildings). I only replaced the script for the first combobox with the one you wrote for me, to test it out. Do I need to replace anything else?

2. If Building01 is the siteName in my XML file and its Data is B1, then I have labeled both the scene and the first frame "B1" as well (each building scene only uses one frame). Am I missing something?

3. If I can get this working :), do I need to do anything different with the scripts for each of the five comboboxes besides replacing [thisXML.load("filename.xml");] with the appropriate xml file and [CBOLoad"filename"]?

Thanks again,
malpeigne
 
To test it I created a new flash movie, added a combobox with the instance name CBOLoadBuildings. I copied your xml file into the same directory as the Flash movie and named it buildings.xml.

Using the exact code above it works ok in that situation. I would have to see yours to get an idea of why it might not be working.

You are jumping scenes with the combo change? That is different from what I did. The code I wrote will jump to a frame label. So you should change that line to:
Code:
_root.gotoAndPlay(""+itemSelected+"",1);

Fixing that might be all you need to get it to work.

When you get this working :) you will have to create a seperate event handler (listener) for each combobox (in addition to a seperate data source).

Wow JT that almost looked like you knew what you were doing!
 
Unfortunately that didn't work either.

And to make matters worse: I copied and pasted the script for each of my comboboxes and changed the event handler and data sources according, but when I tested it the menus would not drop, they only showed their default --Buildings--

Why would adding code to the other menus cause them all to not see the xml data?
 
You didn't change the XML datasources right? You just added the event listeners to each one? Did you name each of the event listener uniquely?

Can you post a zipped copy of your .fla and xml sources? At this point I pretty much need to see it to be of any further assistance.

Wow JT that almost looked like you knew what you were doing!
 
I have a zipped archive all ready, but I can't figure out how to post it...
 
You will have to post it on some public web space. Do you have web server or something that you can use?
 
I get a "Page not Available" from Yahoo. Try again?

Wow JT that almost looked like you knew what you were doing!
 
Instead of clicking the link directly from this page, copy and paste it into the address field above. You should get a message asking to save or open the file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top