码迷,mamicode.com
首页 > 其他好文 > 详细

as3 读取XML和txt

时间:2014-08-11 14:20:32      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:style   io   for   ar   cti   div   new   size   

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

标签:style   io   for   ar   cti   div   new   size   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!