Webservice Component

Somehow, Adobe left the WebService classes out of Flash CS3 and Flash CS4 and made our life difficult. We all want to upgrade our day to day projects to Actionscript 3 but lack this feature we had in AS2. As I see it, Adobe wants all development of data intensive applications and websites, developed on the Flex platform. I can understand this point of view, but it still leaves us behind without any possibility to integrate webservices into our Flash CS3 projects.

I wrote my own implementation for webservices in AS3 for the Flash CS3 IDE and Flash CS4 IDE. It works roughly the same as in Flex although it might miss some features you will find in Flex. I'm planning on refining the classes as of now and adding functionality when needed.

Within a few months this webservice component will be discussed in the newest book from the O'Reilly family: O'Reilly: The ActionScript 3.0 Quick Reference Guide: For Developers and Designers Using Flash CS4 Professional and later also in a new Friends of ED book: Foundation XML and E4X for Flash and Flex (Foundation).

Usage Component

Download the *.mxp installation file of the WebService AS3 Components for Flash CS3 IDE and Flash CS4 IDE.

Components windowOnce installed you can see the component in your Component window in the Flash IDE (if not, reload the window: options > reload). You also might want to make the Component window visible by selecting it from the menu Window > Components.

Drag the following 3 classes into your library: WebService, Operation and OperationEvent. These 3 classes are all necessary for normal use.

Usage Class Library

I've set this project up at Google Code for public use. You can use the Subversion repository to check out the class library at http://code.google.com/p/as3webservice/.

It supports all kinds of arguments for the remote methods and it supports, as far as I could test, all possible responses: Objects, Arrays, Strings, ... and all possible combinations of those.

Example

Use the following code to make use of your freshly installed components:

Actionscript:
  1. import be.wellconsidered.services.WebService;
  2. import be.wellconsidered.services.Operation;
  3.  
  4. import be.wellconsidered.services.events.OperationEvent;
  5.  
  6. var ws = new WebService("http://www.webservicex.net/WeatherForecast.asmx?wsdl");
  7. var op:Operation = new Operation(ws);
  8.  
  9. op.addEventListener(OperationEvent.COMPLETE, onResult);
  10. op.addEventListener(OperationEvent.FAILED, onFault);
  11.  
  12. op.GetWeatherByPlaceName("new york");
  13.  
  14. function onResult(e:OperationEvent):void { trace(e.data); }
  15. function onFault(e:OperationEvent):void { trace(e.data); }

The WebService returns an Object with several properties (temperature, ...) and an Array of Forecasts, which are a Objects as well.

Note: don't hold me responsible for any misbehavior.



Copyright © 2004–2009. All rights reserved.

RSS Feed. This blog is proudly powered by Wordpress and uses Modern Clix, a theme by Rodrigo Galindez.