Comunidad de diseño web y desarrollo en internet online

problema con lector de noticias

Citar            
MensajeEscrito el 18 Sep 2008 04:35 pm
hola este es mi primer post tengo un problema hice un sistema php + sql que genera un xml y este actualiza un swf, en primer momento en flash parseaba los datos del xml a una caja de texto pero vi que esto tenia mas limitacines entonces me puse manos a la obra y emprece a crear otro que crea textfield para los txtos y un mc para l aimagen el problema es que ahora no puedo hacerlo funcionar me sale undefind asi que dedusco que es un problema al tomar los datos del xml

mi codigo es este

Código :

this._lockroot = true;

// creo las cajas donde voy a guardar el texto
this.createTextField("caja1",1,17,37,200,50);
caja1.html = true;
caja1.wordWrap = true;
caja1.multiline = true;
caja1.label.condenseWhite = true;
caja1.focusTextField = null;
var styles_caja1:TextField.StyleSheet = new TextField.StyleSheet();
styles_caja1.load("modulo_noticias/estilos.css");
caja.styleSheet = styles_caja1;

this.createTextField("caja2",2,298,37,200,50);
caja2.html = true;
caja2.wordWrap = true;
caja2.multiline = true;
caja2.label.condenseWhite = true;
caja2.focusTextField = null;
var styles_caja2:TextField.StyleSheet = new TextField.StyleSheet();
styles_caja2.load("modulo_noticias/estilos.css");
caja2.styleSheet = styles_caja2;

this.createTextField("caja3",3,28,212,200,50);
caja3.html = true;
caja3.wordWrap = true;
caja3.multiline = true;
caja3.label.condenseWhite = true;
caja3.focusTextField = null;
var styles_caja3:TextField.StyleSheet = new TextField.StyleSheet();
styles_caja3.load("modulo_noticias/estilos.css");
caja3.styleSheet = styles_caja3;

// creo las cajas donde voy a guardar la imagen
imagen = this.createEmptyMovieClip("imagen",4)
imagen._x = 250;
imagen._y = 100;
ancho = 100;
alto = 100;
item = _root.imagen

//

var indice:Number;
var noticias_xml:XML;


function cargarDatos(_indice:Number){ 
   var titulo:String; 
   var copete:String;
   var mensaje:String;
   var imagen:String;
   
   
   titulo = noticias_xml.firstChild.childNodes[_indice].firstChild.firstChild; 
   copete = noticias_xml.firstChild.childNodes[_indice].firstChild.nextSibling.firstChild.nodeValue;
   mensaje = noticias_xml.firstChild.childNodes[_indice].firstChild.nextSibling.nextSibling.firstChild.nodeValue;
   imagen = noticias_xml.firstChild.childNodes[_indice].lastChild.firstChild;
   
   _root.caja1.text = titulo;
   _root.caja2.text = copete;
   _root.caja3.text = copete;
   _root.imagen.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.php");
noticias_xml.onLoad = function(){
         cargarDatos(indice);         
   }




mi xml es

<noticias>
<noticia>
<titulo>EL SEGURO DE DESEMPLEO. COMO HACER PARA COBRARLO.</titulo>
<copete>Si Ud. fue despedido de su trabajo o se consideró despedido, puede acceder al seguro de desempleo, siempre que cumpla.</copete>
<mensaje>Si Ud. fue despedido de su trabajo o se consideró despedido, puede acceder al seguro de desempleo, siempre que cumpla.</mensaje>
<imagen>ingreso/imagenes/filagente1bis.jpg</imagen>
</noticia>
</noticias>

Si alguien puede hecharme una mano que hace dias que lo estoy viendo y no llego a ingun lado.
muchas gracias

Por ale80262

7 de clabLevel



 

firefox
Citar            
MensajeEscrito el 18 Sep 2008 05:57 pm
Aparte de repetir el mismo código para todas las cajas de texto en vez de utilizar un ciclo y aplicar los estilos a los campos antes de que estos hayan sido leídos, tu código no presenta errores, estos señalamientos no son los causantes de tu problema, me parece que el problema viene del php, veo que tu XML en vez de tildes tiene caracteres extraños, trata de utilizar utf8_encode para las variables con que formas el XML, quizás sea ese el problema.

Por elchininet

Claber

3921 de clabLevel

17 tutoriales

Genero:Masculino  

Front-end developer at Booking.com

firefox
Citar            
MensajeEscrito el 18 Sep 2008 09:15 pm
gracias por tu respuesta el codigo php que me genera el xml que me toma el swf es el siguiente


Código :

<?PHP
$link=mysql_connect("localhost","xxxxx","xxxxx");
mysql_select_db("rl001_rl");

$query = 'SELECT * FROM noticias';
$results = mysql_query($query);

echo "<?xml version=\"1.0\"?>\n";
echo "<noticias>\n";

while($line = mysql_fetch_assoc($results)) {
   
echo "<noticia>\n";   
echo "<titulo>" . $line["titulo"] . "</titulo>\n";
echo "<copete>" . $line["copete"] . "</copete>\n";
echo "<mensaje>" . $line["mensaje"] . "</mensaje>\n"; 
echo "<imagen>". $line["dire2"] . $line["name"] . "</imagen>\n";
echo "</noticia>\n";

}
echo "</noticias>\n";

mysql_close($link);
?>



igual cuando lo hago con texto dinamico m carga bien y cuando lo hago con este codigo tambien (el que pongo a continuacion) me funciona bien pero no pude crear los botones para que sea siguiente o anterior


Código :

this._lockroot = true;

// creo las cajas donde voy a guardar el texto
this.createTextField("caja1",1,17,37,200,50);
caja1.html = true;
caja1.wordWrap = true;
caja1.multiline = true;
caja1.label.condenseWhite = true;
caja1.focusTextField = null;
var styles_caja1:TextField.StyleSheet = new TextField.StyleSheet();
styles_caja1.load("modulo_noticias/estilos.css");
caja.styleSheet = styles_caja1;

this.createTextField("caja2",2,298,37,200,50);
caja2.html = true;
caja2.wordWrap = true;
caja2.multiline = true;
caja2.label.condenseWhite = true;
caja2.focusTextField = null;
var styles_caja2:TextField.StyleSheet = new TextField.StyleSheet();
styles_caja2.load("modulo_noticias/estilos.css");
caja2.styleSheet = styles_caja2;

this.createTextField("caja3",3,28,212,200,50);
caja3.html = true;
caja3.wordWrap = true;
caja3.multiline = true;
caja3.label.condenseWhite = true;
caja3.focusTextField = null;
var styles_caja3:TextField.StyleSheet = new TextField.StyleSheet();
styles_caja3.load("modulo_noticias/estilos.css");
caja3.styleSheet = styles_caja3;

// creo las cajas donde voy a guardar la imagen
imagen = this.createEmptyMovieClip("imagen",4)
imagen._x = 250;
imagen._y = 100;
ancho = 100;
alto = 100;
item = _root.imagen

var my_caja:XML = new XML();
my_caja.ignoreWhite = true;

my_caja.onLoad = function(success:Boolean) {
if (success) {
   
   nicanor = my_caja.firstChild;
   
   
caja.styleSheet = styles_caja;

caja1.text = nicanor.firstChild.childNodes[0].firstChild.nodeValue;
caja2.text = nicanor.firstChild.childNodes[1].firstChild.nodeValue;
caja3.text = nicanor.firstChild.childNodes[2].firstChild.nodeValue;
imagen = nicanor.firstChild.childNodes[3].firstChild.nodeValue;

item.loadMovie(imagen) 
      
         
}
}
my_caja.load("noticias.php");



en el ultimo caso tendria que crear un array que me contenga los datos de que obtine del xml para despues poder hacer en los botones atras y adelante crear una funcion que sume uno a ese array?

bueno muchas grcias de nuevo

Por ale80262

7 de clabLevel



 

firefox
Citar            
MensajeEscrito el 19 Sep 2008 09:13 am
Puedes hacer un array o trabajar directamente con el XML, como más te convenga, la ventaja que obtienes con el array, es que podrías hacer referencias como:

Código ActionScript :

myArray[x].titulo;


En vez de:

Código ActionScript :

myXML.firstChild.childNodes[x].firstChild.nodeValue;


La cual resulta un poco más complicada y engorrosa al trabajar con los datos.

Por elchininet

Claber

3921 de clabLevel

17 tutoriales

Genero:Masculino  

Front-end developer at Booking.com

firefox
Citar            
MensajeEscrito el 19 Sep 2008 10:20 pm
tienes razon muchas gracias lo cambie y ya esta funcionando todo muy bien

Por ale80262

7 de clabLevel



 

firefox

 

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