Comunidad de diseño web y desarrollo en internet online

Menú desplegable desde XML

Citar            
MensajeEscrito el 06 Nov 2007 11:59 am
Muy buenas,
a ver si logro explicarme bien a partir del ejemplo que se puede ver aquí en cristalab (http://www.cristalab.com/tutoriales/186/lector-de-noticias-xml-en-flash-con-imagenes) .

Tenemos las noticias, que cargan desde un xml mediante una función cargarDatos(indice) , pongamos que queremos aparte de desplazar con botones sumando y restando al indice que dice que noticia cargar utilizar un desplegable que nos muestre todas las noticias y al elegir una opción cargue la noticia correspondiente.

Pongo a continuación el xml (le he colocado un id para poder sacar el índice que se corresponda con la noticia que queremos cargar con la funcion cargarDatos(indice)):

Código :

<noticias>
   <noticia nombre="noticia 1" fecha="14/04/2005" id="0"> 
      <titulo>Nave rusa tripulada se acopla sin problemas a la Estación Espacial Internacional</titulo>
      <mensaje>Moscú (dpa) - La nave rusa Soyuz, con tres tripulantes a bordo, se acopló hoy automáticamente sin problemas a la Estación Espacial Internacional (ISS) a las 02:20 GMT del domingo, informó hoy el centro de control de vuelo ruso cerca de Moscú.</mensaje>      
      <image>nave.jpg</image>
   </noticia>   
   <noticia nombre="noticia 2" fecha="25/02/2005" id="1"> 
      <titulo>Finaliza estado de excepción pero crece descontento</titulo>
      <mensaje>Luego de que el presidente de Ecuador, Lucio Gutiérrez, levantara el estado de emergencia decretado en Quito el viernes, las multitudinarias protestas en dicha ciudad exigiendo la dimisión del mandatario empezaron a extenderse a otras regiones y amenazan con abarcar todo el país.</mensaje>      
      <image>vaticano.jpg</image>
   </noticia>   
</noticias>


Ahora el código que carga dentro del desplegable las distintas noticias:

Código :

thisXML = new XML();
thisXML.ignoreWhite = true;
thisXML.onLoad = LoadCombo;
thisXML.load("DATA/noticias.xml");
function LoadCombo(success) {
   if (success) {
      var BaseNode = thisXML.childNodes[0];
      var ComboPromos = new Array();
      var ComboIndice = new Array();
      var ThisNode;
      //add a default item to the combo box
      _root.mi_box.addItem("-- Seleccione Promoción --");
      //get sites information
      for (i=0; i<BaseNode.childNodes.length; i++) {
         ThisNode = BaseNode.childNodes[i];
         ComboPromos[i] = ThisNode.attributes["nombre"];
         ComboIndice[i] = ThisNode.attributes["id"];
         //add to combo box
         _root.mi_box.addItem(ComboPromos[i], ComboIndice[i]);
      }
   }
}


El problema es que no se como hacer para que al elegir una de las opciones le pase el id(indice) a la función cargaDatos(indice) y me muestre el contenido de la noticia correspondiente.

Pego también el código de la funcion cargaDatos:

Código :

System.useCodepage = true;
var noticias_xml:XML;
function cargarDatos(_indice:Number) {
        fecha = noticias_xml.firstChild.childNodes[_indice].attributes.fecha;
        titulo = noticias_xml.firstChild.childNodes[_indice].firstChild.firstChild.nodeValue;
        mensaje = noticias_xml.firstChild.childNodes[_indice].firstChild.nextSibling.firstChild.nodeValue;
        imagen = noticias_xml.firstChild.childNodes[_indice].lastChild.firstChild.nodeValue;
        _root.mensaje_txt.htmlText = "";
        _root.mensaje_txt.htmlText += "<p align='center'><font color='#006633' size='12'><b>"+titulo+"</b></font></p>";
        _root.mensaje_txt.htmlText += "<p><font size='10'>"+mensaje+"</font>";
        _root.mensaje_txt.htmlText += "<font color='#666666' size='10'>Publicado: "+fecha+"</font></p>";
        _root.pantalla_mc.loadMovie(imagen);
}
siguiente_btn.onPress = function() {
        if (noticias_xml.firstChild.childNodes[indice+1] != null) {
                indice++;
                cargarDatos(indice);
        }
};
anterior_btn.onPress = function() {
        if (noticias_xml.firstChild.childNodes[indice-1] != null) {
                indice--;
                cargarDatos(indice);
        }
};
indice = 0;
noticias_xml = new XML();
noticias_xml.ignoreWhite = true;
noticias_xml.load("noticias.xml");
noticias_xml.onLoad = function() {
        cargarDatos(indice);
};


Espero que puedan ayudarme, muchas gracias por adelantado.

Por CristalBal

9 de clabLevel



 

firefox
Citar            
MensajeEscrito el 07 Nov 2007 09:57 am
Estoy analizando tu duda... me interesa el tema.

Por pitger

Claber

201 de clabLevel



Genero:Masculino  

Cáceres

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.