我不太了解xml,遗憾的是我没有多少时间可以学习。
我创建了一个连接到sql数据库并写入字段的php文件
在内部xml结构中:
<?PHP
$link = mysql_connect("localhost","root","");
mysql_select_db("myDatabase");
$query = 'SELECT * FROM users';
$results = mysql_query($query);
echo "<?xml version=\"1.0\"?>\n";
echo "<user>\n";
while($line = mysql_fetch_assoc($results)) {
echo "<item>" . $line["user"]."</item> \n";
}
echo "</user>\n";
mysql_close($link);
?>
这有效,但我需要从swf文件中读取它:
var myXML:XML;
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("http://localhost/users.php"));
myLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void {
myXML = new XML(e.target.data);
trace(myXML);
mytext.text=myXML;
}
如何从Flash管理用户?例如,如果我想操纵第一个用户(用户[0])我该怎么办?
我试图补充一下:
trace(myXML.user);
mytext.text=myXML.user;
但它不起作用,我试图在互联网上找到,但这个论点太过明确。感谢
答案 0 :(得分:1)
您拥有结构XML:
<user>
<item>Ann</item>
<item>Alice</item>
<item>Bob</item>
<item>Cecile</item>
</user>
您的代码中的变量 myXML 指向根节点,即用户。现在,要解决您需要的项目:
// Get all child nodes of the root, whose node name is "item".
var aList:XMLList = myXML.child("item");
// You can also write it = myXML.item; but I don't like this way
// because of possible confusion with XML class methods.
// Now you can access list items which are XML nodes.
// Note that XMLList.length() is a method, not a getter property.
for (var i:int = 0; i < aList.length(); i++)
{
var anItem:XML = aList[i];
// Basically you get all anItem children as XMLList
// which consist of a single text XML node,
// and convert it into a string.
var aName:String = anItem.children().toXMLString();
trace(i, aName);
}