PDA

View Full Version : How do I look for the name of a node that must stored in a variable?



mpc2001
July 7th, 2008, 03:29 AM
Hi. I am trying to write a simple flash app looks for a for certain node in an xml file. The particular node is stored in a variable so that the node can be changed dynamically.How would I write this? so far I have the following code but it doesnt seem to be working. I get this error
1151: A conflict exists with definition diffLevel in namespace internal.

How would I write this correctly?


var diffLevel:String = new String;
var diffLevel= "trdrugbreaks";


var xmlURL:URLRequest = new URLRequest("testObject.xml");
var xmlLoader:URLLoader = new URLLoader(xmlURL);
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
function xmlLoaded(event:Event) {
var dataXML = XML(event.target.data);

trace(dataXML.productCodes.diffLevel);

}

pensamente
July 7th, 2008, 05:01 AM
maybe just typed var 2 times... don't know if theres something more, but try it this way:

var diffLevel:String = new String;
diffLevel= "trdrugbreaks";

once you create a variable, you don't "var" again to change it's value, doing that you are telling flash to create another... in your case with the same name - diffLevel.

hope this helps

mpc2001
July 7th, 2008, 12:34 PM
yeah its still not working.
by typing this: trace(dataXML.productCodes.diffLevel);
I want it to actually trace this
trace(dataXML.productCodes.trdrugbreaks);
It can't be hardcoded because the node is going to be different every tiem the its activated.

mpc2001
July 7th, 2008, 12:47 PM
i did take the extra var off. but it didnt fix it.

devonair
July 7th, 2008, 01:13 PM
try:
trace(dataXML.productCodes.child(diffLevel));

mpc2001
July 7th, 2008, 03:37 PM
Thanks that worked perfectly. I need to get up on my action script 3.

devonair
July 7th, 2008, 06:52 PM
groovy.. glad that helped out..