Ver Mensaje Individual
  #5 (permalink)  
Antiguo 09/10/2011, 06:01
marcwolf
 
Fecha de Ingreso: junio-2010
Mensajes: 353
Antigüedad: 13 años, 10 meses
Puntos: 6
Respuesta: Como actualizar un swf cada x tiempo

hola,
ok mirad,

Tengo un getdata.php (faltan cojer mas datos de la web pero bueno)

Código PHP:
//header("Refresh: 10; URL='getdata.php'");
$context stream_context_create(array('http' => array('timeout' => 5)));
$url file_get_contents('http://www.bolsamania.com/bolsa-cotizaciones/acciones/espana--ibex35.html'0$context);
$doc = new DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTML($url);
$fci $doc->getElementById('ls_table_ficha_cabecera_indice');
$spans $fci->getElementsByTagName('span');
/* chapuza Nº1; pongo la $j prk hay 4 spans con ese id pero solo me interesan 3 */
$j=0;

for (
$i 0$i $spans->length && $j<=2$i++) {
    echo 
$spans->item($i)->nodeValue '<br />';
    
$j++;
}
/*
 *  Creo el xml
 */
    
$zone 3600*1;// España: GMT+1
    
$hora gmdate("G:i"time() + $zone gmdate("I"));
    
$timestamp gmdate("l   d/m/Y   G:i:s"time() + $zone gmdate("I"));

    
// Se crea el XML que guardará la estructura de datos
    
$doc = new DomDocument('1.0','ISO-8859-1');
    
// create root node
    
$xmldata $doc->createElement('data');
    
$xmldata $doc->appendChild($xmldata);
    
$xmldata->setAttribute('timestamp',$timestamp);

        
/* Indices Generales */
        
$indicesgrales $doc->createElement('indicesgrales');
$indicesgrales $xmldata->appendChild($indicesgrales);

/* Creo elementos Xml para Ibex 35 */

  
$indice $doc->createElement('indice');
  
$indice $indicesgrales->appendChild($indice);
  
$indice->setAttribute('nombre',"IBEX 35");
  
$indice->setAttribute('valor',$spans->item(0)->nodeValue);
  
$indice->setAttribute('dif',$spans->item(1)->nodeValue);

  
/* Creo elementos Xml para DOW JONES */

  
$indice $doc->createElement('indice');
  
$indice $indicesgrales->appendChild($indice);
  
$indice->setAttribute('nombre',"DOW JONES");
  
$indice->setAttribute('valor','0');
  
$indice->setAttribute('dif','0%');
  
/* Creo elementos Xml para BORSA BCN MID-50 */

  
$indice $doc->createElement('indice');
  
$indice $indicesgrales->appendChild($indice);
  
$indice->setAttribute('nombre',"BORSA BCN MID-50");
  
$indice->setAttribute('valor','0');
  
$indice->setAttribute('dif','0%');

  
/* Imprimir xml */
 
$filename="dataeconomia";
  
print_r ("<p style='font-family:Arial; font-size:16px'>Salvando fichero: <b>" $filename ".xml</b></p>");
    
$doc->save($filename ".xml"); 
Que genera un xml
Código XML:
Ver original
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <data ..>
  3. <indicesgrales>
  4.     <indice nombre="IBEX 35" valor="8.225,40" dif="-1,54%"/>
  5.     <indice nombre="DOW JONES" valor="0" dif="0%"/>
  6.     <indice nombre="BORSA BCN MID-50" valor="0" dif="0%"/>
  7. </indicesgrales>
  8. </data>

Después de action script tengo esto.

Código Action Script:
Ver original
  1. // Tenemos que poner esto para no
  2. // tener problemas con las tildes
  3. // y otros caracteres especiales
  4. System.useCodepage = true;
  5. // Con esto evitamos que Flash interprete
  6. // los saltos de línea del xml como nodos
  7. // en blanco
  8. XML.prototype.ignoreWhite = true;
  9. datos_txt.autoSize = "left";
  10. // definimos el objeto XML
  11. datos_xml = new XML();
  12. // Cuando se carguen los datos ejecutaremos
  13. // la función cargarDatos
  14. datos_xml.onLoad = cargarDatos;
  15. // Definimos el array donde almacenaremos
  16. // los datos de los borsa
  17. borsa_array = new Array();
  18. // la función cargarDatos se invoca cuando
  19. // hago la llamada a datos_xml.load("borsa.xml");
  20. // al final del código
  21. function cargarDatos(exito) {
  22.     // si el xml se ha cargado bien...
  23.     if (exito) {
  24.         // en el array borsaCargados meto los
  25.         // nodos <borsa> de segundo nivel, pero
  26.         // como todavía no están en el formato
  27.         // que nos interesa, nos lo vamos a recorrer
  28.         // y cada elemento lo pasamos como parámetro
  29.         // a la función pasar_a_array que daja la
  30.         // información a nuestro gusto
  31.         borsaCargados = this.firstChild.childNodes;
  32.         for (var k = 0; borsaCargados[k]; k++) {
  33.             pasar_a_array(borsaCargados[k]);
  34.         }
  35.         // una vez convertidos los datos, eliminamos
  36.         // los objetos que ya no vamos a necesitar, así
  37.         // liberamos memoria
  38.         delete borsaCargados;
  39.         delete datos_xml;
  40.         // muestro los borsa
  41.         verborsa();
  42.     } else {
  43.         // si no se a cargado bien...
  44.         // aquí las sentencias en caso de error
  45.         // durante la carga
  46.         // trace("fallo en la carga");
  47.     }
  48. }
  49. // esta función es la que va ha convertir
  50. // cada nodo en un objeto con propiedades
  51. // más fácil de controlar. Se invoca
  52. // desde la función cargarDatos dentro del for
  53. function pasar_a_array(nodo) {
  54.     // defino el objeto
  55.     var objetoBorsa = new Object();
  56.     // atributos->matriz de atributos del nodo
  57.     var atributos = nodo.attributes;
  58.     // asigno todos los atributos dentro
  59.     // de las propiedades del objeto
  60.     /*for (item in atributos) {
  61.     objetoBorsa[item] = atributos[item];
  62.     }*/
  63.     /* id="1" nombre="IBEX 35" valor="8.225,40" dif="-1,54%" */
  64.     objetoBorsa.nombre = atributos.nombre;
  65.     objetoBorsa.valor = atributos.valor;
  66.     objetoBorsa.dif = atributos.dif;
  67.     objetoBorsa.id = Number(atributos.id);
  68.     // finalmente, añado el objeto al array
  69.     borsa_array.push(objetoBorsa);
  70. }
  71. // función que escribe la lista de borsa dentro
  72. // de la caja de texto. Se invoca desde la función
  73. // cargarDatos
  74. function verborsa() {
  75.     borsa = "";
  76.     for (var i = 0; borsa_array[i]; i++) {
  77.         borsa += "<b>"+borsa_array[i].nombre+" Valor: "+borsa_array[i].valor+"</b> - Diff.: <b>"+borsa_array[i].dif+"</b><br>";
  78.     }
  79.     // quito el último <br>
  80.     borsa = borsa.substring(0, borsa.length-4);
  81. }
  82. datos_xml.load("dataeconomia.xml");
  83. stop();

Grácias,