Tutorial "FLEX" #002 Request server-side data (UrlLoader)

Source: Internet
Author: User

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)

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.