hide side navigation
    5 most recent
    Web Services
    Library's
    Component's
    Applications
    Articles
  Flash button as Flex icon  Flex form by email  Hello Remoting with AS3  AS3 Saving data from Flash  AS3 Loading data into Flash  Fire Effect  Contact form  Dragable buttons  Hello World with openamf  Loading helper classes  Upload with Flash 8  Transitions effects  Snapshot with Flash 8  Hello World Remoting AS2  Flash AS2 Remoting Connector  Saving data from Flash  Loading data into Flash  FlashCom & Remoting login  Cell Renderer API  Editing a table using remoting components  Flash MX2004 web service classes  Browsing a catalog  amfphp Documentation  Hello World Remoting  Online Store with AMFPHP  Flash clients for Web Services  Web Service Walk Though with NuSoap  Popup windows in flash with javascript  Installing Apache/PHP  MoreOver News Feeds  Load Edit Save Text Files via CGI  Save Movie Clip Postion via PHP and MySQL
Current Page (2) << Previous Page | Next Page >> 1 | 2 | 3 | 4 | 5

The ActionScript

The following Actionscript is the basic code needed. Hopefully the comments make the code self-explainitory. The next example will include lots of debugging and other features.

 import mx.services.*;
/* import all of the webservices class packages. 
Note: if you do not use the above import statement you will have to 
call the web service with the full path (new mx.services.WebService(..) */
                                                                       
// set it up so that the service is called when the button is pressed.
result_btn.onPress = function() {
    
    
// Create a new instance of web service called - stockservice.
    
var stockservice = new WebService("http://www.flash-db.com/services/ws/companyInfo.wsdl");

    
// Call the doCompanyInfo method and assign it to the pending call object to handle results.
    
stockResultObj stockservice.doCompanyInfo("any","any","macr");
    
    
stockservice.onLoad trace("loading");
    
    
// the onResult function is called if the service is successful
    
stockResultObj.onResult = function(result) {
    
        
// example result values.  The result is a decoded actionscript object
        //version of the xml returned by the operation.
        // In this case the result is a object with company, lastPrice etc being properties.
        
trace("company Name: "+result.company);
        
trace("lastPrice: "+result.lastPrice);
        
trace("volume: "+result.volume);
        
trace("yearHigh: "+result.yearHigh);
        
trace("yearLow: "+result.yearLow);
        
    }

    
stockResultObj.onFault = function(fault) {
        
// If there is any error such as the service not working, the onFault handler will be invoked.
          
trace(fault.faultCode "," fault.faultstring);
    }

To test, copy the above actionscript and place on the first frame of your movie. Then 'Test Movie'. The output window should display something like:

loading
company Name: MACROMEDIA INC
lastPrice: 26.95
volume: 1676392
yearHigh: 28.80
yearLow: 6.00

So the above code works well and is fairly easy to use, but what about if you need to debug or more closely follow the interactions of a more complicated web service - we'll get to this on the next page.

Current Page (2) << Previous Page | Next Page >> 1 | 2 | 3 | 4 | 5