PDA

View Full Version : Passing a Variable from an XML Datasource


futureruins
10-11-2002, 05:34 PM
Hi,

I am trying to populate a combo box with an XML datasource, and then pass a variable based on the selection...this is what I've tried, but no luck : | Thanks to whomever helps!

thisXML = new XML();
thisXML.ignoreWhite = true;
thisXML.onLoad = LoadCombo;
thisXML.load("works.xml");
function LoadCombo(success) {
if (success) {
var BaseNode = thisXML.childNodes[0];
var ComboSites = new Array();
var ComboURLs = new Array();
var ThisNode;
CBOLoadSites.addItem("-- choose --");
for (i=0; i<BaseNode.childNodes.length; i++) {
ThisNode = BaseNode.childNodes[i];
ComboSites[i] = ThisNode.attributes["workName"];
ComboURLs[i] = ThisNode.attributes["workURL"];
CBOLoadSites.addItem(ComboSites[i], ComboURLs[i]);
}
}
}
CBOLoadSites.setChangeHandler(getPick);

function getPick(CBOLoadSites){
//to show the data:
trace(CBOLoadSites.getSelectedItem().data);
}

stop();

hangalot
10-14-2002, 02:41 AM
is the onload event triggering -- check!, put a trace in if not
try switching the 2 sections i took out around=...


function LoadCombo(success) {
if (success) {
var BaseNode = thisXML.childNodes[0];
var ComboSites = new Array();
var ComboURLs = new Array();
var ThisNode;
CBOLoadSites.addItem("-- choose --");
for (i=0; i<BaseNode.childNodes.length; i++) {
ThisNode = BaseNode.childNodes[i];
ComboSites[i] = ThisNode.attributes["workName"];
ComboURLs[i] = ThisNode.attributes["workURL"];
CBOLoadSites.addItem(ComboSites[i], ComboURLs[i]);
}
}
thisXML.load("works.xml");



else u might be walking around wrongly in u'r tree...

futureruins
10-15-2002, 08:45 PM
Well, the onLoad event is working, because the combo box is filling out with the labels in the XML file, but I am unable to make any action occurr when one of the choices is selected...

confused and still new to this...errrgg

futureruins
10-15-2002, 08:50 PM
Here are the files, maybe that could give someone a clue as to how foolish I am ;)

hangalot
10-15-2002, 09:25 PM
instead of setting the event handler in AS, i just used the properties taskbar (of the combobox)2 point it 2 the getPick method, this worked.
as far as retrieving the info from the combobox --> use the getValue() method... ;)

futureruins
10-15-2002, 09:40 PM
I tried what you are saying, but what do I put in the change handler box:

1)

CBOLoadSites.setChangeHandler(getPick); function getPick(CBOLoadSites){ trace(CBOLoadSites.getValue().data);}

2)

(getPick); function getPick(CBOLoadSites){ trace(CBOLoadSites.getValue().data);}

3)

function getPick(CBOLoadSites){ trace(CBOLoadSites.getValue().data);}

4)

trace(CBOLoadSites.getValue().data);

I tried all of these and got no trace back in my testing movie.


Still confused, but i am really thankful for your assistance!!! :)

hangalot
10-15-2002, 09:44 PM
just put getPick there

hangalot
10-15-2002, 09:45 PM
just put getPick or _root.getPick -- i cannot remember but one of the 2, i think 1st

futureruins
10-15-2002, 09:48 PM
Yayyyy! It worked. THANK YOU THANK YOU THANK YOU:D

hangalot
10-15-2002, 09:51 PM
sure took me long enough :D

fututre tip --> this question is better suited 2 the actionscripts forum