<? XML version = "1.0" encoding = "UTF-8"?>
<Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml" layout = "vertical" creationcomplete = "avithandle ()">
<Mx: SCRIPT>
<! [CDATA [
Import MX. rpc. Events. faultevent;
Import MX. rpc. Soap. WebService;
Import MX. rpc. Events. resultevent;
Import MX. Controls. Alert;
Public Function avithandle (): void
{
VaR Web: WebService = new WebService ();
Web. WSDL = "http: // localhost: 2250/flex % 203.0% 20asp.net % 20 test/webservicetest. asmx? WSDL ";
// The loadwsdl method must be called to download the WS description file. Otherwise, the WebService method is not responded even if it is called.
Web. loadwsdl ();
// Added the listener for successful call
Web. addeventlistener (resultevent. Result, wshandle );
// Add an error call listener
Web. addeventlistener (faultevent. Fault, fault );
Web. readxml. Send ();
}
// The processing function is successfully called.
Public Function wshandle (E: resultevent): void
{
// DDD. Text = E. result as string;
VaR menus: xml = XML (E. result as string );
VaR results: xmllist = menus. Children ();
VaR array: array = elementtoattr (results );
Datagrid1.dataprovider = array;
}
/* Convert the following types of XML into an array to bind data to the DataGrid, tree, and other components as dataprovider.
<? XML version = "1.0" encoding = "UTF-8"?>
<Items>
<Item>
<Name> nam1 </Name>
<Grender> boy </grender>
<From> Guangxi </from>
</Item>
<Item>
<Name> nam2 </Name>
<Grender> boy </grender>
<From> Shanghai </from>
</Item>
</Items>
*/
Public Function elementtoattr (results: xmllist): Array
{
VaR array: array = new array ();
For each (VAR child: XML in results ){
VaR OBJ: Object = new object ();
OBJ [Child. nodekind ()] = Child [Child. nodekind ()];
For each (VAR ite: XML in child. Children ()){
OBJ [ite. Name (). tostring ()] = Child [ite. Name (). tostring ()];
}
/*
OBJ ["name"] = Child. Name;
OBJ ["grender"] = Child. grender;
OBJ ["from"] = Child. From;
*/
Array. Push (OBJ );
}
Return
Array;
}
// Error handling function
Public Function fault (E: faultevent): void
{
Alert. Show (E. fault. faultstring, 'error ')
}
]>
</MX: SCRIPT>
<Mx: Label text = "label" id = "DDD" fontsize = "12"/>
<Mx: DataGrid id = "datagrid1">
<Mx: columns>
<Mx: datagridcolumn headertext = "name" datafield = "name"/>
<Mx: datagridcolumn headertext = "gender" datafield = "grender"/>
<Mx: datagridcolumn headertext = "" datafield = "from"/>
</MX: columns>
</MX: DataGrid>
</MX: Application>