Comunidad de diseño web y desarrollo en internet online

Cargando XML a nuestro .SWF

Citar            
MensajeEscrito el 19 Mar 2009 11:28 am
Bueno, esta duda la tengo hace mucho... y desde entonces no la puedo solucionar.

Yo por ejemplo, tengo este XML:

Código :

<novedades>
   <noticia>
      <titulo>Testnoticia 1</titulo>
      <texto>El martes..</texto>
   </noticia>
   <noticia>
      <titulo>Testnoticia 2</titulo>
      <texto>el miercoles</texto>
   </noticia>
   <noticia>
      <titulo>Testnoticia 3</titulo>
      <texto>el jueves..</texto>
   </noticia>
   <noticia>
      <titulo>Testnoticia 4</titulo>
      <texto>el viernes..</texto>
   </noticia>
        <noticia>
      <titulo>Testnoticia 5</titulo
      <texto>el sabado...</texto>
   </noticia>
</novedades>


Y este AS3 para cargarlo...

Código :

var xmlLoader:URLLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, showXML);
xmlLoader.load(new URLRequest("caca.xml"));

function showXML(e:Event):void {
XML.ignoreWhitespace = true; 
var news:XML = new XML(e.target.data);
trace("cantidad de etiquitas: " + news.noticia.length());
total.text = "Total de etiquetas: " + news.noticia.length();

var i:Number;
for (i=0; i < news.noticia.length(); i++) {
//trace(" Name of the song: "+ songs.track[i].title.text());
//trace(" Name of the Band: "+ songs.track[i].band.text());
titulo.text = news.noticia[i].texto.text();
trace("Novedad: "+ news.noticia[i].texto.text());
}
}


El problema, es que por ejemplo.. al hacer un trace de news.noticia[i].texto.text(), salen barbaro los 5 textos.. pero si los muestro en un txt dinamico.. me muestra el ultimo, y asi con otros intentos....

Pero yo lo que quiero, es un visualizador de noticias... al hacer click en el boton "XSig" cargue el siguiente nodo "noticia"... y asi sucesivamente.. hasta que se acaben los nodos.. luego los nodos "titulo" y "texto" serian cargados en txt dinamicos al stage.

Quiero, que por favor, me digan si me malexplico... ps.. es algo que me esta comiendo tiempo que no tengo xD.

Gracias :D

Por Stranyer

38 de clabLevel



 

unknown
Citar            
MensajeEscrito el 19 Mar 2009 04:48 pm
Dado que lo asignas al mismo campo de texto, es lógico que se sobreescriba:

titulo.text = news.noticia[i].texto.text();

Si no es eso lo que quieres, usa campos de textos distintos en cada pasada, o créalos en el momento con new TextField()

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 20 Mar 2009 08:41 am

Pero yo lo que quiero, es un visualizador de noticias... al hacer click en el boton "XSig" cargue el siguiente nodo "noticia"... y asi sucesivamente.. hasta que se acaben los nodos.. luego los nodos "titulo" y "texto" serian cargados en txt dinamicos al stage.

Perdona que te corrija. Lo que quieres es cargar un fichero XML y, al con unos botones XSig y XAnt, mostrar en una caja de texto el título y texto que se correspondería al nodo que fuera.

Vamos, Stranyer, debes usar una variable (p.e. index), además conviene hacer una función

Código ActionScript :

var index:Number=0; //<--al principio
.....cargamos el XML......
....la función  showXML(e:Event) quedaría como
function showXML(e:Event):void {
    ....
    mostrarNoticia(0)
}
...una función para el botón siguiente
function btsiguienteOnPress(e:Event):void{
    index++
    mostrarNoticia(index)
}
...una función para el botón anterior
function btanteriorOnPress(e:Event):void{
    index--
    mostrarNoticia(index)
}
//y nuestra función mostrarNoticia como
function mostrarNoticia(index:Number){
    //mostramos el título y el texto
    titulo.text = news.noticia[index].titulo.text();
    texto.text=news.noticia[index].texto.text()
}

Por Eliseo2

710 de clabLevel



 

firefox
Citar            
MensajeEscrito el 20 Mar 2009 12:23 pm
Buenisimo :wink:

Ahora, si yo quisiera listar, por titulo cada noticia... en forma de lista... y convertidos en boton.. cosa de abrir la noticia que quiera, guiandome por el titulo. Como hago?

Me explico?

Por Stranyer

38 de clabLevel



 

unknown

 

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