|
-
Senior Member
[AS3]How do i generate xml in php and load in flash?
I want to read info from my database in xml format into flash using as3, via php? Can anyone please guide me on how to achieve this?
-
OOP is one letter from OOPS
-
Senior Member
I am currently using the following codes, but it isn't working, any idea?
PHP CODE:-
Code:
<?php
header("content-type: text/xml");
$output="";
$output='<Books>'."\n";
$output.='<Book ISBN=123456>'."\n";
$output.='<Title>Kulu Manali</Title>'."\n";
$output.="<Author>Me Me</Author>\n";
$output.="</Book>\n";
$output.="<Book ISBN=542631>\n";
$output.="<Title>Ghost Buster</Title>\n";
$output.="<Author>Unknown</Author>\n";
$output.="</Book>\n";
$output.="<Book ISBN=654312>\n";
$output.="<Title>Inu Yasha</Title>\n";
$output.="<Author>My Favourite</Author>\n";
$output.="</Book>\n";
$output.="</Books>";
echo "<xmp>".$output."</xmp>";
?>
FLASH Code:
Code:
import flash.text.*;
import flash.events.*;
import flash.display.*;
import flash.xml.*;
import flash.net.*;
xml_txt.text="Handling Request";
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("interface_php/xmltest.php"));
function LoadXML(e:Event):void
{
xmlData = new XML(e.target.data);
xml_txt.text=xmlData;
}
xml_txt is a dynamic textbox on stage, and it, when run, shows only "Handling Request", nothing else! Any idea or suggetions?
-
OOP is one letter from OOPS
One thing I am noticing is that you did not put quote marks around your attributes <Book ISBN=542631> should be <Book ISBN='542631'>. In XML all attributes have to be in quote marks regardless of the type. Also, I do not think you actually need the \n unless you are doing that for some specific reason I am not aware of.
-
Senior Member
yeh you are right about the qoutes.....and i tried without \n, but without it, there is formatting error! Anyway, thanks for solving my problem!
-
use amfphp. I have a great polling script in as2 and 3, but truthfuly this protocol is way better for any use... Im currently using it in a mutliplayer turn based game im developing.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|