最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
as 3读取xml实现代码
时间:2022-06-28 22:17:57 编辑:袖梨 来源:一聚教程网
as 3读取xml实现代码
as3对xml的操作实在是太方便了(e4x ecmascript for xml 没错.就是ecmascript 如果js比较好的同学对这个也很熟悉吧)..
package
{
import flash.display.*;
import flash.text.*;
import flash.xml.*;
import flash.net.*;
import flash.events.event;
public class classsubfeed extends sprite
{
var temp:textfield;
var myxmlurl:urlrequest;
var myloader:urlloader;
var xmlurl:string;
var xmlcontent:xml;
public function classsubfeed()
{
temp = new textfield();
temp.x = 10;
temp.y = 10;
temp.;
temp.;
temp.border = true;
temp.bordercolor = 0x669900;
temp.multiline = true;
temp.htmltext = 'loading.....';
addchild(temp);
// xml地址
xmlurl = "http://www.111com.net/xml/5230.xml";
this.loadxml(xmlurl);
}
private function loadxml(xmlurl:string):void
{
myxmlurl = new urlrequest(xmlurl);
myloader = new urlloader(myxmlurl);
myloader.addeventlistener(event.complete, onloaded);
}
private function onloaded(event):void
{
xmlcontent = xml(myloader.data);
temp.htmltext = '已经读取feed,正在准备.....';
this.parsedata(xmlcontent);
}
private function parsedata(xmlcontent:xml):void
{
var rrstitle:string = xmlcontent.channel.title;
var rrslink:string = xmlcontent.channel.link;
temp.htmltext = "" + rrstitle + "
";
for each(var item:xml in xmlcontent..item)
{
var itemtitle:string = item.title.tostring();
var itemlink:string = item.link.tostring();
temp.htmltext += "
";
}
}
}
}
实例二,读取外部xml 文件
------------------------------readxml.as-------------------------------------------package
{
import flash.events.event;
import flash.net.urlloader;
import flash.net.urlrequest;
import flash.xml.xmldocument;
import flash.text.textfield;
import flash.text.textformat;
import flash.text.textfieldautosize;
import flash.display.displayobjectcontainer;
import flash.display.spritepublic class readxml extends sprite
{
private var myxml:xml;
private var myloader:urlloader;
private var string:string;
private var mystr:string=new string();
private var myxmlurl:urlrequest;
private var txt:textfield=new textfield();
private var format:textformat = new textformat();
public function readxml(myxmlurl:string):void
{
myxmlurl=new urlrequest(myxmlurl);
myloader=new urlloader();
myloader.addeventlistener(event.complete,xmlloaded);
myloader.load(myxmlurl);
}
public function xmlloaded(evt:event):void
{
myxml=new xml(evt.currenttarget.data);
mystr=this.myxml.question[0].@value;
txt.text=mystr;
txt.autosize = textfieldautosize.left;
txt.background = true;
txt.border = true;
format.font = "宋体";
format.color = 0x000000;
format.size = 15;
format.underline = false;txt.defaulttextformat=format;
txt.x=50;
txt.y=200;
trace(myxml);
trace(mystr);
}
public function returntext(target:displayobjectcontainer):void
{
target.addchild(txt);
}
}//end of class
}//end of package
相关文章
- 重返未来1999趋光性研究夜幕之外怎么玩 12-27
- 桃源深处有人家养怡尘世装饰大赛怎么玩 12-27
- 第五人格贪吃蛇大作战联动时装怎么样 12-27
- 绝区零直到苍白荒秽之地怎么玩 12-27
- 第五人格贪吃蛇大作战联动时装怎么样 贪吃蛇联动独特时装介绍 12-27
- 以闪亮之名龙族幻想联动怎么玩 以闪亮之名龙族幻想联动介绍 12-27