How to use Flex WebService Component in Flash

1.) Prepare done the Flex SDK

2.) Import rpc.swc / Frameworks.swc into Flash

3.) Drag a DataGrid component into stage ( Instance Name : myDG )

4.) Use the following Sample Code

import mx.rpc.soap.*; 
import mx.core.*; 
import mx.rpc.events.*; 
import fl.data.DataProvider; 
  
var foo:WebService = new WebService(); 
  
foo.addEventListener( "load", loadDone); 
  
foo.loadWSDL( "http://www.webservicex.net/country.asmx?WSDL" ); 
  
var myOperation:Operation; 
  
function loadDone(evt:LoadEvent) 
{ 
  myOperation = Operation( foo.getOperation("GetCountries") ); 
   
  myOperation.addEventListener( "fault", wsError ); 
  myOperation.addEventListener( "result", wsResult ); 
   
  myOperation.send(); 
} 
  
function wsError(evt:FaultEvent) 
{ 
  trace(evt); 
} 
  
function wsResult(evt:ResultEvent) 
{ 
  var xml:XML = XML(evt.result); 
  var dp:DataProvider = new DataProvider(xml); 
  myDG.dataProvider = dp; 
}

posted on 2011-05-14 11:32  Morris  阅读(246)  评论(0编辑  收藏  举报

导航