Tratar de obtener la URL de XML en SWF como hacer clic en un vínculo

  • joerugg
  • Born
  • Born
  • No Avatar
  • Registrado: Sep 16, 2009
  • Mensajes: 1
  • Status: Offline

Nota Septiembre 16th, 2009, 7:56 am

Hola a todos...

Mi primer post aquí, así que por favor, sea amable!

Ive sido la construcción de un mapa en flash que obtiene la mayor parte de su información desde un archivo XML. Todo parece funcionar bien con la excepción de las URL de enlaces a otras páginas de nuestro sitio.

La idea es usuario hace clic en una ciudad en el mapa, información sobre la ciudad que aparece en un cuadro de información común en el SWF - Esta información incluye enlaces a la página de las ciudades. Todo pasa por el XML en el archivo SWF correctamente, con la excepción de los enlaces / URL.

Heres una muestra de mi código XML, que está siendo cargado en mi swf. (URL fueron despojados por el software del foro, pero es obvio que van):

XML Código: [ Select ]
<?xml version="1.0" encoding="utf-8"?>
 
<site>
   <pages>
 
      <page page_number="1">
         <town>NEW LONDON</town>
         <title>New London Headline Goes Here</title>
         <date>Date Goes Here ...</date>
         <content>Short abstract of town here ...</content>
         <link><a href='URL GOES HERE'>VISIT TOWN PAGE</a></link>
         <image>zip06logo.png</image>
      </page>
 
      <page page_number="2">
         <town>NORTH STONINGTON</town>
         <title>North Stonington Headline Goes Here</title>
         <date>Date Goes Here ...</date>
         <content>Short abstract of town here ...</content>
         <link><a href='URL GOES HERE'>VISIT TOWN PAGE</a></link>
         <image>zip06logo.png</image>
      </page>
   </pages>
 
</site>
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <site>
  4.    <pages>
  5.  
  6.       <page page_number="1">
  7.          <town>NEW LONDON</town>
  8.          <title>New London Headline Goes Here</title>
  9.          <date>Date Goes Here ...</date>
  10.          <content>Short abstract of town here ...</content>
  11.          <link><a href='URL GOES HERE'>VISIT TOWN PAGE</a></link>
  12.          <image>zip06logo.png</image>
  13.       </page>
  14.  
  15.       <page page_number="2">
  16.          <town>NORTH STONINGTON</town>
  17.          <title>North Stonington Headline Goes Here</title>
  18.          <date>Date Goes Here ...</date>
  19.          <content>Short abstract of town here ...</content>
  20.          <link><a href='URL GOES HERE'>VISIT TOWN PAGE</a></link>
  21.          <image>zip06logo.png</image>
  22.       </page>
  23.    </pages>
  24.  
  25. </site>


Heres y el (tijeras) con el código del documento de Flash.:

ACTIONSCRIPT Código: [ Select ]
//Create a holder that will contain the title, content and image.
var holder:MovieClip = new MovieClip();
holder.addChild(townText);
holder.addChild(titleText);
holder.addChild(dateText);
holder.addChild(contentText);
holder.addChild(linkText);
 
//Add the holder to the stage
addChild(holder);
 
//Hide the holder at the beginning of the movie.
//We don't want to show any content before the title, content and image has
//been loaded.
holder.visible = false;
 
// BUTTON CODE HERE
 
// END BUTTON CODE
 
//Specify the path to the XML file.
//You can use my path or your own.
var xmlFilePath:String = "test.xml";
 
// LOAD XML
 
//We save the loaded XML data into a variable
var XMLData:XML;
 
//Load the XML file.
//We call the xmlDataLoaded() function when the loading is complete.
var loader = new URLLoader();
loader.load(new URLRequest(xmlFilePath));
loader.addEventListener(Event.COMPLETE, xmlDataLoaded);
 
//This function is called when the XML file is loaded
function xmlDataLoaded(e:Event):void {
 
   //Create a new XML object from the loaded XML data
   XMLData = new XML(loader.data);
   XMLData.ignoreWhitespace = true;
 
   //Call the function that adds event listeners for the buttons
   addEventListeners();
 
   // EVENT LISTENERS FOR BUTTONS ALL 38 OF 'EM - CODE SNIPPED
 
   //Loop through the pages found in the XML file
   for each (var page:XML in XMLData.pages.page) {
 
      //Check if the page number that we're looking is found from the XML data.
      //The "page.@page_number" refers to the page's "page_number" attribute in the XML file.
      if (page. @ page_number == pageNumber) {
 
         //Set the title from the XML
         titleText.text = page.title;
 
         //Set the town from the XML
         townText.text = page.town;
 
         //Set the title from the XML
         dateText.text = page.date;
         linkText.htmlText = page.link;
         contentText.text = page.content;
 
         
         //Load the image (the image path is specified in the XML)
         var imageLoader = new Loader();
         imageLoader.load(new URLRequest(page.image));
 
         //Listen when the image is loaded
         imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
 
         //We can exit the loop now
         break;
      }
   }
}
  1. //Create a holder that will contain the title, content and image.
  2. var holder:MovieClip = new MovieClip();
  3. holder.addChild(townText);
  4. holder.addChild(titleText);
  5. holder.addChild(dateText);
  6. holder.addChild(contentText);
  7. holder.addChild(linkText);
  8.  
  9. //Add the holder to the stage
  10. addChild(holder);
  11.  
  12. //Hide the holder at the beginning of the movie.
  13. //We don't want to show any content before the title, content and image has
  14. //been loaded.
  15. holder.visible = false;
  16.  
  17. // BUTTON CODE HERE
  18.  
  19. // END BUTTON CODE
  20.  
  21. //Specify the path to the XML file.
  22. //You can use my path or your own.
  23. var xmlFilePath:String = "test.xml";
  24.  
  25. // LOAD XML
  26.  
  27. //We save the loaded XML data into a variable
  28. var XMLData:XML;
  29.  
  30. //Load the XML file.
  31. //We call the xmlDataLoaded() function when the loading is complete.
  32. var loader = new URLLoader();
  33. loader.load(new URLRequest(xmlFilePath));
  34. loader.addEventListener(Event.COMPLETE, xmlDataLoaded);
  35.  
  36. //This function is called when the XML file is loaded
  37. function xmlDataLoaded(e:Event):void {
  38.  
  39.    //Create a new XML object from the loaded XML data
  40.    XMLData = new XML(loader.data);
  41.    XMLData.ignoreWhitespace = true;
  42.  
  43.    //Call the function that adds event listeners for the buttons
  44.    addEventListeners();
  45.  
  46.    // EVENT LISTENERS FOR BUTTONS ALL 38 OF 'EM - CODE SNIPPED
  47.  
  48.    //Loop through the pages found in the XML file
  49.    for each (var page:XML in XMLData.pages.page) {
  50.  
  51.       //Check if the page number that we're looking is found from the XML data.
  52.       //The "page.@page_number" refers to the page's "page_number" attribute in the XML file.
  53.       if (page. @ page_number == pageNumber) {
  54.  
  55.          //Set the title from the XML
  56.          titleText.text = page.title;
  57.  
  58.          //Set the town from the XML
  59.          townText.text = page.town;
  60.  
  61.          //Set the title from the XML
  62.          dateText.text = page.date;
  63.          linkText.htmlText = page.link;
  64.          contentText.text = page.content;
  65.  
  66.          
  67.          //Load the image (the image path is specified in the XML)
  68.          var imageLoader = new Loader();
  69.          imageLoader.load(new URLRequest(page.image));
  70.  
  71.          //Listen when the image is loaded
  72.          imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
  73.  
  74.          //We can exit the loop now
  75.          break;
  76.       }
  77.    }
  78. }


Pensé que se declara:

ACTIONSCRIPT Código: [ Select ]
linkText.htmlText = page.link;


...sería suficiente, pero appare notly no. La URL se muestra, pero no es un enlace. (Ive también estableció el cuadro de texto dinámico para linkText a HTML).

Cant averiguar qué Im que hace mal aquí....

Gracias por la ayuda que puede dar.

= X
  • Anonymous
  • Bot
  • No Avatar
  • Registrado: 25 Feb 2008
  • Mensajes: ?
  • Loc: Ozzuland
  • Status: Online

Nota Septiembre 16th, 2009, 7:56 am

  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • Avatar de Usuario
  • Registrado: May 28, 2003
  • Mensajes: 23404
  • Loc: Woodbridge VA
  • Status: Offline

Nota Septiembre 16th, 2009, 8:17 am

Creo que tienes que hacer algo como esto:
http://www.kirupa.com/forum/showthread.php?t=323063

Ver swooters respuesta.
"There's no place like 127.0.0.1 except for ::1."
Alexandria Networks. Leader in IT consulting for associations/non-profits, and small to medium sized businesses around the northern Virginia and Washington D.C. metro area.

Publicar Información

  • Total de mensajes en este tema: 2 mensajes
  • Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 44 invitados
  • No puede abrir nuevos temas en este Foro
  • No puede responder a temas en este Foro
  • No puede editar sus mensajes en este Foro
  • No puede borrar sus mensajes en este Foro
  • No puede enviar adjuntos en este Foro
 
 

© 2011 Unmelted, LLC. Ozzu® es una marca registrada de Unmelted, LLC