Comunidad de diseño web y desarrollo en internet online

parseo de respuesta de URLLoader

Citar            
MensajeEscrito el 16 Dic 2008 02:44 pm
Hola a todos,

No tengo claro que medios existen en Flex para parsear la respuesta que devolve URLLoader.

El tipo de datos URLLoaderDataFormat.VARIABLES

El fichero del servidor es muy simple
test.php
<? echo "entradas=2&title=bla&body=test"; ?>

Haciendo trace de event.target.data
me devolve %3C%3F%20echo%20%22entradas=2&title=bla&body=test%22%3B%20%3F%3E%0D%0A

Me pregunto como puedo alcanzar las variables?

Un cordial saludo, Victoria

Por skywalker

28 de clabLevel



Genero:Femenino  

firefox
Citar            
MensajeEscrito el 16 Dic 2008 05:56 pm
Prueba:

event.target.data.entradas
event.target.data.title

Aunque parece que te devuelve el texto planop con el echo incluido, lo que quiere decir que no lo estás probando en un servidor que interprete PHP (tienes que mirarlo en el navegador o usar rutas absolutas)

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 17 Dic 2008 01:32 pm
Gracias!
Pero de esta forma no puedo


Código :

package news {
   import flash.net.*
   import flash.events.*
   public class noticia{
      
      private const NEWS_URL:String = "news.php";
      private const DATA_FORMAT:String = URLLoaderDataFormat.VARIABLES;
      
      public function noticia(){
      }
      public function getNews(){
         //URLRequest - class capture all data from single html request
         var req:URLRequest = new URLRequest(NEWS_URL);
         req.method = URLRequestMethod.POST;
         var variables:URLVariables = new URLVariables();
         req.data = variables;
         var ldr:URLLoader = new URLLoader();
         ldr.dataFormat = DATA_FORMAT;
         ldr.load(req);
         ldr.addEventListener(Event.COMPLETE, parceNews);
      }
      
      public function parceNews(event:Event):String{
         var mynews = event.target.data as String;
         return mynews;

      }
   }
}


El codigo dentro de pelicula es siguente

Código :

import news.noticia;
var noticias:noticia = new noticia();
var lista:String = noticias.getNews();
m_text.htmlText=lista.entradas;  
m_text1.htmlText=lista.body; 
m_text2.htmlText=lista.title;  


Me devolve
1119: Access of possibly undefined property entradas through a reference with static type String.

Algo estoy haciendo mal?

El hosting soporta php.

Gracias de nuevo.

Por skywalker

28 de clabLevel



Genero:Femenino  

firefox
Citar            
MensajeEscrito el 17 Dic 2008 01:56 pm
Si getNews devuelve un objeto, tendría que ser:

var lista:Object = noticias.getNews();

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 17 Dic 2008 03:40 pm
Skyalter, te está devolviendo como si fuera ¡¡un fichero de texto!!

Por Eliseo2

710 de clabLevel



 

firefox
Citar            
MensajeEscrito el 18 Dic 2008 08:17 am
Gracias de nuevo!
He probado con object, pero me da el mismo error

"TypeError: Error #1009: No se puede acceder a una propiedad o a un método de una referencia a un objeto nulo."

Intennto que la funcion me devolve un array y no tengo claro porque dentro de la funcion me alcanza los valores del array y en la pelicula me salta otra vez Error #1009

noticia.as

Código :

public function parceNews(event:Event):Array{
         
         var mynews:Object = event.target.data;
         var newsArr:Array = new Array();
         
         newsArr['title']= mynews.title;
         newsArr['body']= mynews.body;
         trace(newsArr['title']); //devolve valor correcto
         trace(newsArr['body']); //devolve valor correcto
         return newsArr;
      }



Codigo dentro de pelicula

Código :

import news.noticia;
var noticias:noticia = new noticia();
var lista:Array = noticias.getNews();
trace(lista['title']);   //devolve undefined!
trace(lista['body']);  //devolve undefined!

//devolve error Error #1009!.

Creo que me esta escpando algo, pero no tengo claro que. No entiendo porque esta vacio el array en la pelicula si el metodo devolve el array correctamente?.

Y otra pregunta, puedo hacer un var_dump o alguna cosa parecida en flex para ver todo el array para poder debugar?

Gracias a todos.

Por skywalker

28 de clabLevel



Genero:Femenino  

firefox

 

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