Using convertParametersHandler in Flex 4

There is avery handy API in Flex 4 RemoteObject and WebService. It lets you manipulate/validate parameters before calling the actual operation.

Suppose I have imported WebService http://ws.cdyne.com/WeatherWS/Weather.asmx?wsdl in FlashBuilder 4 . The service basically gives weather information.  I want to validate/Change parameter ‘ZIPCODE’ of ‘GetCityWeatherByZIP’ when a service call happens. Here is what you need to do. In servicename.as class,

public class Weather extends _Super_Weather
{

	public function Weather() {

		_serviceControl.convertParametersHandler = convertParameterHandler;

	}

	public function convertParameterHandler(o:Array):Array {
//Dummy validation. If user gives '210' as value. Prefix it with '90' (Beverly Hills:-)
		var str:String = o[0];
		if(str.substr(0,2)!="90") //User gives only last 3 digits
			str = "90"+str;
		o[0] = str;
		return o;
	}

}

}
Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s