2 Replies Latest reply on Jan 7, 2010 2:34 PM by Gregory Lafrance

    Newbie Q: HTTPService in ActionScript

    jsd99 Level 3

      I'm a complete newbie - I've watched the "learn flex in a week" stuff and read a few tutorials but otherwise I am starting from scratch.  I'm trying to create an HTTPService object purely in ActionScript, mainly because I think it just looks cleaner than having all the pieces in separate functions, object declaration tags, etc.  Feel free to convince me that stylistically that is the wrong choice.


      I've started by doing it the other way, which is in all the examples.  This loads an object full of configuration data.  One of the elements is another URL that needs to be loaded, so I did this:


               private function configLoadedOK(event:ResultEvent):void {
                   config = event.result.thisMoment;
                   var metadataHTTP:HTTPService = new HTTPService;
                   metadataHTTP.url = config.LINKS.GET_META_DATA.value;
                   metadataHTTP.fault = function():void {
                       Alert.show("Unable to load metadata.", "Error");
                   metadataHTTP.result = function(metaevent:ResultEvent):void {
                       metadata = metaevent.result.moment_info;
                       trace("metadata loaded " + metadata);


      It won't compile.  The "metadataHTTP.fault = " and "metadataHTTP.result = " lines are giving the following error: "1119: Access of possibly undefined property fault through a reference with static type mx.rpc.http.mxml:HTTPService."


      In the documentation it lists fault and result as events of the HTTPService class.  I guess you can't just set an event the way you'd set a property?  How do you do it?

        • 1. Re: Newbie Q: HTTPService in ActionScript
          msakrejda Level 4

          Note that there is an implementation of  HTTPService in two packages: mx.rpc.http.mxml and mx.rpc.http. The former is intended to be used in mxml documents, and I think this might be why you're having problems, although I'm not sure exactly what's going on.

          • 2. Re: Newbie Q: HTTPService in ActionScript
            Gregory Lafrance Level 6

            When you specify event handlers in AS, you need to use addEventListener():


            <?xml version="1.0" encoding="utf-8"?> 
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                  import mx.rpc.events.FaultEvent;
                  import mx.rpc.events.ResultEvent;
                  import mx.rpc.http.mxml.HTTPService;
                  private function init():void{
                    var metadataHTTP:HTTPService = new HTTPService;
                    metadataHTTP.url = "www.google.com";
                    metadataHTTP.addEventListener(FaultEvent.FAULT, faultFunc);
                    metadataHTTP.addEventListener(ResultEvent.RESULT, resultFunc);
                  private function faultFunc(evt:FaultEvent):void{        
                  private function resultFunc(evt:ResultEvent):void{        

            If this post answers your question or helps, please mark it as such.

            Greg Lafrance - Flex 2 and 3 ACE certified


            Flex / AIR Development, Training, and Support Services