Why does flex need to request the server to read the data instead of reading it by itself?
Flex is an interface language, mainly to do interface display, it can achieve a lot of brilliant effect, this is the traditional Web project department can compare. However, it does not have good support for database and file read/write.
Since flex does not have good support for databases and read-write files, reading data and reading and writing files can be written in C # or Java, and then flex requests interfaces written in C # or Java.
There are many ways to request a service-side interface from Flex, and this way I'll explain how to use Urlloader to request an interface.
to request a service-side interface:
1. Create the URLRequest object, set the type of the requested Url,method (Post,get), and the parameters of the request pass
2, create the Urlloader object to request the interface. (Remember to pass the urlrequest into the Urlloader load method)
3, processing the returned data
code example (code snippet):
//method of requesting the service side (UrlLoader)protectedfunction Mytree_creationcompletehandler (Event: flexevent):void{//1. Create a URLRequest object, set the requested URL and method type (get,post), request parameter (data) varurlrequest:urlrequest=Newurlrequest (); Urlrequest.url="http://192.168.116.64:9986/Manage/ComponentManage/AjaxHandler/F_ElementToXML.ashx?type=getElement"; Urlrequest.method=Urlrequestmethod.post; varParam:urlvariables =NewUrlvariables (); Param.name="Zhongxia"; Param.age=" -";//2, create the Urlloader, and assign the URLRequest object to the Urlloader load method, and register the event varUl:urlloader=NewURLLoader (); Ul.load (URLRequest); Ul.addeventlistener (Event.complete,handler);}//Urlloader Processing of request completionPrivatefunction Handler (e:event):void{ //3. Read the data (the data is stored in the event object e), do the action you want to do varJsonstring:string=e.target.data asString;//here is the operation of the data varJson:object =Com.adobe.serialization.json.JSON.decode (jsonstring); vararr:arraycollection=NewArrayCollection (JSON asArray) Mytree.dataprovider=arr;}
Tutorial "FLEX" #002 Request server-side data (UrlLoader)