Connecting Tech Pros Worldwide Help | Site Map

changing actionscript to read php/mysql instead of xml

anfetienne's Avatar
Needs Regular Fix
 
Join Date: Feb 2009
Location: UK
Posts: 356
#1: Jul 18 '09
is it possible to change the below code so it reads arrays that php creates and uses it to display the images and captions instead of reading from xml? the purpose of this is because there is not actual html as all codes are stored in a db and all images and clips etc are linked in using http:// links instead of your local /image.jpg etc

i know the main focus is from lines 5 to 9

Expand|Select|Wrap|Line Numbers
  1.     function loadXML(loaded)
  2.     {
  3.         if (loaded)
  4.         {
  5.             xmlNode = this.firstChild;
  6.             total = xmlNode.childNodes.length;
  7.             for (i = 0; i < total; i++)
  8.             {
  9.                 _root.small_image[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
  10.                 _root.big_image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
  11.                 _root.description[i] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;
  12.                 if (i == 0)
  13.                 {
  14.                     _root.loadGImage(_root.description[i], _root.big_image[i]);
  15.                 } // end if
  16.                 ++_root.total_images;
  17.             } // end of for
  18.             createSmall();
  19.             _root.downloadButton._visible = true;
  20.         }
  21.         else
  22.         {
  23.             content = "file not loaded!";
  24.         } // end else if
  25.     } // End of the function
  26.     xmlData = new XML();
  27.     xmlData.ignoreWhite = true;
  28.     xmlData.onLoad = loadXML;
  29.     if (_root.xml_file == undefined)
  30.     {
  31.         _root.xml_file = "images.xml";
  32.     } // end if
  33.     xmlData.load(xml_file);
  34. } // End of the function
  35.  
flexteacher's Avatar
Newbie
 
Join Date: Jul 2009
Location: good book
Posts: 4
#2: Jul 18 '09

re: changing actionscript to read php/mysql instead of xml


root.xml_file = "images.php";



php do you press the screen, I let my skin again attribution xml server
anfetienne's Avatar
Needs Regular Fix
 
Join Date: Feb 2009
Location: UK
Posts: 356
#3: Jul 20 '09

re: changing actionscript to read php/mysql instead of xml


Quote:

Originally Posted by flexteacher View Post

php do you press the screen, I let my skin again attribution xml server

i dont understand what you mean?
gopan's Avatar
Member
 
Join Date: Apr 2009
Location: Kochi (COK), India
Posts: 41
#4: Aug 14 '09

re: changing actionscript to read php/mysql instead of xml


Dear anfetienne,
I hope you know that the flash cannot directly take data from mysql. it can take data as xml or variables... in case of large data we prefer xml.

So all you have to do is to echo the data with a php as an xml. You see the below example...

Expand|Select|Wrap|Line Numbers
  1. newsfeed.php
  2.  
  3. <?php 
  4.  header('Content-Type: text/xml');
  5.  echo '<?xml version="1.0"?>
  6. <doc xml:base="http://thenewsflash.net/" xmlns:xlink="http://www.w3.org/1999/xlink">';
  7.  $query = "SELECT ddate,heading,matter FROM news ORDER BY ddate DESC";
  8.  $result = mysql_query($query,$link) or die('Fatal error occured! Inform <a href="mailto:webmaster@thenewsflash.net">webmaster</a>');
  9.  $rec = mysql_num_rows($result);
  10.  echo ' <news totrec="'.$rec.'">';
  11.  $i= 1;
  12.  while ($row = mysql_fetch_assoc($result)) {
  13.     $matq=$row["matter"];
  14.     $matq=str_replace ("\r\n","<br>",$matq);
  15.     $matq=htmlspecialchars($matq,ENT_QUOTES);
  16.     echo '  <newsrow id="'.$i.'" heading="'.$row["heading"].'" date="'.$ddate.'" mattr="'.$matq.'"/>';
  17.     $i++;
  18.  }
  19.  mysql_free_result($result);
  20.  mysql_close($link);
  21.  echo ' </news>
  22. </doc>';
  23. ?>
  24.  
and replace xmlData.load("newsfeed.xml") to xmlData.load(newsfeed.php)
Reply