0 Replies - 607 Views - Last Post: 18 May 2009 - 12:47 AM

#1 nade93  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 29-October 07

problem with XML and flash loading

Posted 18 May 2009 - 12:47 AM

Hi All

I am trying to load data from mysql to xml to flash using actionscript and php. Im doing something wrong but not sure what.

Basically, my php file (latestnews.php) looks like this
<?php

header("Content-type: text/xml");


$host = "host";
$user = "user";
$pass = "password";
$database = "dbname";

$linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host.");
mysql_select_db($database, $linkID) or die("Could not find database.");

$query = "SELECT * FROM latestnews ORDER BY timestamp DESC LIMIT 0,3";
$resultID = mysql_query($query, $linkID) or die("Data not found.");

$xml_output = "<?xml version=\"1.0\" encode=\"UTF-8\"?>\n";
$xml_output = "<!DOCTYPE data[
			   <!ELEMENT headline (text, date)>
			   <!ATTLIST headline name CDATA #REQUIRED>
			   <!ELEMENT text (#PCDATA)>
			   <!ELEMENT date (#PCDATA)>
			   ]>\n";
$xml_output .= "<entries>\n";

for($x = 0; $x < mysql_num_rows($resultID); $x++){
	$row = mysql_fetch_assoc($resultID);
	$xml_output .= "\t<entry>\n";
	
	$xml_output .= "\t\t<headline name=\" ". $row['headline'] . "\">\n";
		// Escaping illegal characters
		$row['content'] = str_replace("&", "&", $row['content']);
		$row['content'] = str_replace("<", "<", $row['content']);
		$row['content'] = str_replace(">", "&gt;", $row['content']);
		$row['content'] = str_replace("\"", "&quot;", $row['content']);
	$xml_output .= "\t\t<text><![CDATA[" . $row['content'] . "]]></text>\n";
	$xml_output .= "\t\t<date><![CDATA[" . $row['timestamp'] . "]]></date>\n";
	$xml_output .= "\t</headline>\n";
	$xml_output .= "\t</entry>\n";
}

$xml_output .= "</entries>";

echo $xml_output;

?>




this produces the following xml layout
<entries>
−
<entry>
−
<headline name=" This is a Test News">
<text>Test News Description</text>
<date>2009-05-17 19:40:33</date>
</headline>
</entry>
−
<entry>
−
<headline name=" Site launch 21st May 2009">
−
<text>
test news
</text>
<date>2009-05-17 19:38:50</date>
</headline>
</entry>
−
<entry>
−
<headline name=" This is another test news">
<text>Test news news news news</text>
<date>2009-05-17 00:00:00</date>
</headline>
</entry>
</entries>


my actionscript is then as follows

myXML = new XML();
		myXML.ignoreWhite = true;
		myXML.load("admin/includes/latestnews.php");
		myXML.ref = this;
		
		myXML.onload = function(success){
		if(success){
			var root = this.firstChild;
			nodes = root.childNodes;
			for(var i=0; i<nodes.length; i++) {		
				this.ref["Title_txt"+i].htmlText = nodes[i].attributes.name;
				subnodes = nodes[i].childNodes;
				this.ref["Comments_txt"+i].htmlText = subnodes[0].firstChild.toString();
				this.ref["Date_txt"+i].htmlText = subnodes[1].firstChild.toString();
			}
		} else trace("Error loading XML document");
	} 


this is placed in the same frame number as the dynamic text fields but on a seperate layer. The dynamic text fields are:

Title_txt
Comments_txt
Date_txt

There is no output error but nothing is showing up. The file is using actionscript 2.0 and wondering if the actionscript i am using is write for that format?

any help would be great, bit of a novice with xml loading!

Is This A Good Question/Topic? 0
  • +

Page 1 of 1