首页 > 代码库 > as3 读取XML和txt
as3 读取XML和txt
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.text.TextField;
public class Test extends Sprite {
var textField:TextField;
var arrDirty:Array;
var arrName:Array;
public function Test() {
textField = new TextField();
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, OnComTxtComplete);
loader.load(new URLRequest("dirty_words_config.txt"));
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, OnComXmlComplete);
xmlLoader.load(new URLRequest("random_name.xml"));
}
private function OnComXmlComplete(e:Event):void
{
var xml:XML = new XML(e.target.data);
arrName = new Array();
var name:XML;
for each (name in xml.random_firstname.element)
{
var firstName:String = name.@m_firstName;
arrName.push(firstName);
}
for each (name in xml.random_name_m.element)
{
var lastNameMan:String = name.@m_lastName;
if (lastNameMan != "")
{
arrName.push(lastNameMan);
}
}
for each (name in xml.random_name_w.element)
{
var lastNameWomen:String = name.@m_lastName;
if (lastNameWomen != "")
{
arrName.push(lastNameWomen);
}
}
var iDirty:int;
var iName:int;
var iSzName:int;
var iSzDirty:int;
var szDirty:String;
var szName:String;
for(iName = 0; iName < arrName.length; ++iName)
{
for(iDirty = 0; iDirty < arrDirty.length; ++iDirty)
{
szName = arrName[iName];
szDirty = arrDirty[iDirty];
if(szName.indexOf(szDirty) >= 0)
{
trace(szName + " " + szDirty);
break;
}
/* for(iSzName = 0; iSzName < szName.length; ++iSzName)
{
for(iSzDirty = 0; iSzDirty < szDirty.length; ++iSzDirty)
{
var tmpName:String = szName.charAt(iSzName);
var tmpDirty:String = szDirty.charAt(iSzDirty);
if(tmpName == tmpDirty)
{
trace("单词相同 szName:" + szName + " szDirty:" + szDirty);
trace(iName + " " + iDirty + " " + iSzName + " " + iSzDirty);
}
}
}*/
}
}
trace("done");
}
private function OnComTxtComplete(e:Event):void
{
textField.text = e.target.data;
arrDirty = new Array();
arrDirty = textField.text.split("\r");
}
}
}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。