# Calling a WebService using Flash/AS3

**URL:** <https://forum.kirupa.com/t/calling-a-webservice-using-flash-as3/313578>\
**Category:** open source\
**Created:** [September 3, 2010, 4:55am UTC](https://forum.kirupa.com/t/calling-a-webservice-using-flash-as3/313578 "2010-09-03T04:55:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [September 3, 2010, 4:55am UTC](https://forum.kirupa.com/t/calling-a-webservice-using-flash-as3/313578/1 "2010-09-03T04:55:29Z")

</div>

Hi everyone,  
It seems like the WebService classes have been removed for AS3 projects created in Flash. Fortunately, the Flash Builder libraries work in Flash projects, so I’ve created a small example involving a web service that uses the Flash Builder SWC files in a Flash CS4 project.

In order to build the example, make sure you have Flash Builder 4 installed. Also make sure your Library path contains a pointer to the Flash Builder libraries. On my computer it is: `C:\Program Files (x86)\Adobe\Adobe Flash Builder 4\sdks\4.1.0\frameworks\libs` You can set/modify that in the ActionScript 3.0 Settings dialog.

The code is basically:

```auto

package 
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import mx.rpc.soap.*;
	import mx.rpc.events.*;
	import mx.rpc.AbstractOperation;

	public class MainDocument extends MovieClip
	{
		private var movieWebService:WebService;
		private var serviceOperation:AbstractOperation;

		public function MainDocument()
		{
			// setting up an event with an event handler
			startButton.addEventListener(MouseEvent.CLICK, SetupWebService);
		}

		function SetupWebService(event:MouseEvent):void
		{
			movieWebService = new WebService();
			movieWebService.loadWSDL("http://www.kirupafx.com/WebService/TopMovies.asmx?WSDL");

			movieWebService.addEventListener(LoadEvent.LOAD, BuildServiceRequest);
		}

		function BuildServiceRequest(evt:LoadEvent)
		{
			serviceOperation = movieWebService.getOperation("GetMovieAtNumber");
						
			serviceOperation.addEventListener(FaultEvent.FAULT, DisplayError);
			serviceOperation.addEventListener(ResultEvent.RESULT, DisplayResult);
			
			serviceOperation.send([GenerateRandomNumber(0,9)]);
		}

		function DisplayError(evt:FaultEvent)
		{
			trace("error");
		}
		
		function DisplayResult(evt:ResultEvent)
		{
			var movieName:String = evt.result as String;
			movieText.text = movieName;
		}
		
		function GenerateRandomNumber(min:int, max:int):int
		{
			return Math.floor(Math.random()*(1+max-min))+min;
		}
	}
}

```

I’ll have a tutorial written on this soon, but I wanted to post this up here in the interim.

Cheers,  
Kirupa 😜
