Sunday CG received a network of friends of the problem, request the use of Flash ActionScript from the server to read dynamically generated data and analysis, input to the user interface of the small program today to share the code, the realization process is very simple for beginners to learn, but also hope that the old bird to correct.
Requirements: Under the BS structure, the client uses Flash to read the dynamically generated XML format data from the server, and to parse and send the obtained data to the interface display.
XML format:
The code is as follows |
Copy Code |
<root> <username uid= "ceshi001″> <title>sdfsdf</title> <beginTime>2009-10-10</beginTime> <endTime>2009-10-01</endTime> <currentMoney>56456</currentMoney> <state> Good </state> <isMember> No www.111cn.net</ismember> </username> <username uid= "www.111cn.net″> <title>dfgdfgdfg</title> <beginTime>2009-10-10</beginTime> <endTime>2009-10-01</endTime> <currentMoney>23</currentMoney> <state> Good </state> <isMember> No </isMember> </username> </root> |
Requires resolution to a single User object and saved using array, where the user object contains the data in the XML
The properties
Main code:
The code is as follows |
Copy Code |
Package { Import Flash.display.Sprite; Import flash.events.*; Import Flash.net.URLLoader; Import Flash.net.URLRequest; Import flash.xml.*;
public class Flashxml extends Sprite { UserInfo Business Object Instance private var bui:buserinfo = new Buserinfo (); XML cache private Var Xmldata:xml; User List private Var Userlist:array;
Constructor Public Function Flashxml () { Loading XML Loadxml (); } /** * Method Name: Loadxml * Function: Load external XML data */ Private Function Loadxml (): void{ var loader:urlloader = new Urlloader (); Setting up loader event sniffing Configurelisteners (loader); URL Request object, getting the URL from the configuration class var request:urlrequest = new URLRequest (Applicationconfig.requesturl); try { Loader.load (Request); } catch (Error:error) { Trace ("Load XML error."); } }
/** * Method Name: Configurelisteners * Function: Set object's Event monitor */ Private Function Configurelisteners (dispatcher:ieventdispatcher): void { Load complete Dispatcher.addeventlistener (Event.complete, Completehandler); Set Read completion event bindings Dispatcher.addeventlistener (Event.complete, Completehandler); Capturing security errors and IO errors Dispatcher.addeventlistener (Securityerrorevent.security_error, Securityerrorhandler); } /** * Method Name: Completehandler * Function: After XML data is loaded, operation */ Private Function Completehandler (event:event): void { var loader:urlloader = Urlloader (event.target); This. XmlData = new XML (loader.data); UserList = Bui. Getuserinfolist (XmlData); This. Xmlparse () }
/** * Method Name: Securityerrorhandler * Function: Flash Security Configuration Restrictions */ Private Function Securityerrorhandler (event:securityerrorevent): void { Trace ("Securityerror:" + event); }
/** * Method Name: Ioerrorhandler * Function: IO error */ Private Function Ioerrorhandler (event:ioerrorevent): void { Trace ("IOError:" + event); }
/** * Method Name: Xmlparse * Function: Simple test for parsing xml */ Private Function Xmlparse (): void { Traversal of user Array For each (Var user:userinfo in userlist) { Trace (User.getuid ()); Trace (User.gettitle ()); Trace (User.getbegintime ()); Trace (User.getendtime ()); Trace (User.getcurrentmoney ()); Trace (User.getstate ()); Trace (User.getismember ()); } } } } |
Code Description UserInfo is an entity class that contains all of the user's information, Buserinfo is
The business-tier basic business class of the UserInfo entity, which contains a list of all users that return
Getuserinfolist () method