Flash and Runtime Sharing of WebService Classes (No More Errors!)



If you’ve dealt with Flash MX Pro 2004 and runtime sharing of the WebServiceClasses component, then you’ve most likely run into errors during compilation. Under normal circumstances, you drag the WebServiceClasses into your movie, compile, and off you go. For larger applications you might find that it makes more sense to create some sort of shared assets library.

I stumbled across this a few months ago when converting the SensorLogic M2M Portal to Flash. We make extensive use of the WebServiceClasses component and it didn’t make sense to include it in every single Flash file. So we created a shared assets library and used the same little 25kB component over and over.

Once we integrated Flash into our automated build process we ran into some major headaches when compiling. We were basically checking to see if the IDE threw any errors when compiling all of our .flas. Of course the compiler complains when the WebServiceClasses do not exist in the movie that references them. They’ll exist during runtime, because they’ve been preloaded. Yet the IDE isn’t smart enough to know this.

So here comes a workaround that I found to be EXTREMELY useful. If you try to compile a movie that has the following code:

import mx.services.*;
var ws:WebService = new WebService(”http://www.xmethods.net/sd/2001/TemperatureService.wsdl”);
var wsResult:PendingCall = ws.getTemp(”75214″);
wsResult.onResult = function(result)
{
trace(result);
}

and doesn’t have a WebServiceClasses component in it’s library you’ll get the following error:

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 2: The class ‘WebService’ could not be loaded.
var ws:WebService = new WebService(”http://www.xmethods.net/sd/2001/TemperatureService.wsdl”);

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 3: The class ‘PendingCall’ could not be loaded.
var wsResult:PendingCall = ws.getTemp(”75214″);

Total ActionScript Errors: 2 Reported Errors: 2

So to suppress this error you need to place a few intrinsic class files in your ActionScript Classpath. These files are simply stubs that specify which methods are contained within the class, but the compiler does not check their validity. If you’d like to see an example check out the Boolean.as file. The class files are generally located at:

C:\Documents and Settings\Username\Local Settings\Application Data\Macromedia\Flash MX 2004\en\Configuration\Classes

So I ultimately placed a WebService, SOAPCall, and PendingCall intrinsic class file in the following location:

C:\Documents and Settings\Username\Local Settings\Application Data\Macromedia\Flash MX 2004\en\Configuration\Classes\mx\services

Now my .flas compile with no problems at all. If you’d like to see an example of this technique please feel free to download the following zip file and place the intrinsic class files at the location listed above. Be sure to unzip all of the files into a single location and run them. The main file that you’ll want to test with is called “temperature_service.fla”. I would recommend trying to run it intially (to see the errors), then place the intrinsic class files in their correct location and try again. It should work and if not please feel free to drop me a line!

Click here to download the sample files.



Comments are closed.