hi all..
i've a Services class...which handles the HTTPService requests and responses and faults. Now i want to dispatch a new event whenever i send request to the server...so that i can take custom actions like showing some popup window or disabling certain components...but i'm not able to figure out a way to do it...i'm sure that it is quite simple for most of you..but i'm just not able to figure a way to do it...here is my services class:
PHP Code:
package business
{
import mx.controls.Alert;
import mx.managers.CursorManager;
import mx.rpc.AsyncToken;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;
import view.Privileges_Form;
public class Services
{
private const ENDPOINT_URL:String = "../getPrivilegeDetails.php";
private static var servicesLocator:Services;
private var gateway:HTTPService;
public static function getInstance() : Services
{
if ( servicesLocator == null )
{
servicesLocator = new Services();
}
return servicesLocator;
}
public function Services()
{
if ( servicesLocator != null )
{
throw new Error( "Only one Services instance should be instantiated" );
}
Privileges_Form.
gateway=new HTTPService();
gateway.resultFormat="e4x";
gateway.url = ENDPOINT_URL;
gateway.method = "POST";
gateway.useProxy = false;
gateway.addEventListener(ResultEvent.RESULT, resultHandler);
gateway.addEventListener(FaultEvent.FAULT, faultHandler);
}
public function doRequest(method_name:String, parameters:Object, callback:Function):void
{
CursorManager.setBusyCursor();
// add the method to the parameters list
parameters['method'] = method_name;
gateway.request = parameters;
var call:AsyncToken = gateway.send();
call.method_name=method_name;
call.request_params = gateway.request;
call.handler = callback;
}
private function resultHandler(e:ResultEvent):void
{
CursorManager.removeBusyCursor();
if(e.result.data.elements("error").length()>0)
{
errorMessageHandler(e);
}
else
{
e.token.handler.call(null,e);
}
}
private function faultHandler(e:FaultEvent):void
{
CursorManager.showCursor();
var errorMessage:String = "Connection error: " + e.fault.faultString;
if (e.fault.faultDetail)
{
errorMessage += "\n\nAdditional detail: " + e.fault.faultDetail;
}
Alert.show(errorMessage);
gateway.cancel();
CursorManager.removeBusyCursor();
}
private function errorMessageHandler(e:ResultEvent):void
{
Alert.show("Error Occured:"+e.result.data.error);
CursorManager.removeBusyCursor();
}
}
}
the method doRequest calls the HTTPServices send method...so in this method, i want to dispatch a new event and handle it in the main application...
can someone please help me in solving this problem..??
thanks in advance...