As3 reads XML and txt

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 ");}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.