As3 reads XML and txt
Last Update:2014-08-11
Source: Internet
Author: User
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.tar get. data); arrname = new array (); var name: XML; For each (name in XML. random_firstname.element) {var firstname: String = [email protected] _ firstname; arrname. push (firstname);} for each (name in XML. random_name_m.element) {var lastnameman: String = [email protected] _ lastname; If (lastnameman! = "") {Arrname. Push (lastnameman) ;}for each (name in XML. random_name_1_element) {var lastnamewomen: String = [email protected] _ 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 ("word identical szname:" + szname + "szdirty:" + szdirty ); trace (INAME + "" + idirty + "" + iszname + "" + iszdirty) ;}}*/} trace ("done ");}
Private function oncomtxtcomplete (E: Event): void {textfield. TEXT = e.tar get. data; arrdirty = new array (); arrdirty = textfield. text. split ("\ r ");}}}