/** * Sends a request to a service using the Flex HTTPService class. The service is expected to return XML data. * NOTE: This function can only be accessed and used within the context of a Form Guide. * @param url The URL to query for the request. * @param resultHandler Function to call when data is successfully retrieved. Expected format: function(data:XML):void. * @param faultHandler Function to call when an error occurs while attempting to send the request. Expected format: * function(fault:String):void. */ function send(url, resultHandler, faultHandler) { if (xfa.host.name != "Flash") return; // ActionScript in Guide (Flex) space import mx.rpc.http.HTTPService; import mx.rpc.events.ResultEvent; import mx.rpc.events.FaultEvent; var service:HTTPService = new HTTPService(); service.url = url; service.resultFormat = "e4x"; // specify that ResultEvent.result should be an XML object // add result (success) event handler service.addEventListener ( ResultEvent.RESULT, function(event:ResultEvent):void { // The XML object is a "Top Level" object in Flex which means we don't need to import the class. // result is an AS3 XML object var data:XML = event.result as XML; if (resultHandler) resultHandler.call(null, data); } ); // add fault (failure) event handler service.addEventListener ( FaultEvent.FAULT, function(event:FaultEvent):void { if (faultHandler) faultHandler.call(null, event.fault.faultDetail); } ); // send the request to the URL service.send(); }