首页 > 其他 > 详细

as3 读取XML和txt

时间:2014-08-11 14:20:32      阅读:413      评论:0      收藏:0      [点我收藏+]
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");
}
}
}

as3 读取XML和txt,布布扣,bubuko.com

as3 读取XML和txt

原文:http://www.cnblogs.com/loying/p/3904419.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!