Ver Mensaje Individual
  #2 (permalink)  
Antiguo 22/10/2006, 15:06
Avatar de luistar
luistar
 
Fecha de Ingreso: marzo-2005
Ubicación: Argentina
Mensajes: 939
Antigüedad: 19 años, 1 mes
Puntos: 0
en tu código: obj_xml[subMenu].childNodes
qué es: objeto_xml ? es un nodo?, si es el primero nodo padre del XML, estás procediendo mal, si es un nodo hijo y de posicion subMenu, el valor de subMenu debe ser un número, no una cadena
creo que andas algo confuso con XML

aver si te ayuda este ejemplo:

el archivo menu.xml
Código HTML:
<?xml version="1.0" encodign="UTF-8"?>
<XMLmenu>
	<botonpadre nombre="menu1" otroattributo="algo1">
		<botonhijo nombre="submenu1" otroattributo="subalgo1"/>
		<botonhijo nombre="submenu2" otroattributo="subalgo2"/>
		<botonhijo nombre="submenu3" otroattributo="subalgo2"/>
	</botonpadre>
	<botonpadre nombre="menu2" otroattributo="algo2"/>
	<botonpadre nombre="menu3" otroattributo="algo3"/>
</XMLmenu> 
el codigo .as
Código:
var obj_xml:XML = new XML();
obj_xml.ignoreWhite = true;
obj_xml.onLoad = function(ok):Void{
	if(ok) mostrar_menu(this.firstChild.childNodes);
	else trace('error');
}
//-------------->
//creamos funciones para facilitarnos la lectura de los attributos en el XML
var atributo_de_padre:Function = function(posicion_xml_padre:Number,attributo:String):String{
	return obj_xml.firstChild.childNodes[posicion_xml_padre].attributes[attributo];
}
var atributo_de_hijo:Function = function(posicion_xml_padre:Number,posicion_xml_hijo:Number,attributo:String):String{
	return obj_xml.firstChild.childNodes[posicion_xml_padre].childNodes[posicion_xml_hijo].attributes[attributo];
}
//-------------->
var mostrar_menu:Function = function(menu_items:Array):Void{
	//exploramos la lista de nodos padre
	for(var n=0; n<menu_items.length; n++){
		trace(atributo_de_padre(n,'nombre')+' - '+atributo_de_padre(n,'otroattributo'));
		//exploramos la lista de cada nodo hijo
		var submenu_item:Array = menu_items[n].childNodes;
		for(var m=0; m<submenu_item.length; m++){
			trace("\t"+atributo_de_hijo(n,m,'nombre')+' - '+atributo_de_hijo(n,m,'otroattributo'));
		}
	}
	//esas funciones anteriores la podeos usar para consultar cualquier atributo tomando encuenta la posicion que ocupan en el xml los nodos
	trace("-------------------------------------")
	trace(atributo_de_padre(0,'nombre')); //el atributo 'nombre' del primer nodo "botonpadre"
	trace(atributo_de_padre(0,'otroattributo')); //el atributo 'otroattributo' del primer nodo "botonpadre"
	trace(atributo_de_hijo(0,1,'nombre')); //el atributo 'nombre' del segundo nodo hijo del primer nodo padre
	trace(atributo_de_hijo(0,0,'otroattributo')); //el atributo 'otroattributo' del primer nodo hijo del primer nodo padre
	//etc
}
//-------------->
obj_xml.load('menu.xml');

stop();
__________________
Si digo que soy mentiroso. ¿Lo soy?

Última edición por luistar; 22/10/2006 a las 15:12