Request.Wait.Load.

Posted by Zu on November 29, 2007 in Flex |

I’ve Never Been Clever ‘Cause Need It Never  

This has been a major issue for me for a very long time, and now i see that many people are having the same problem.

 This is what i wanted to do:

  • Flex calls a url request to webFocus, which make me a brand new XML file.
  • Flex waits for the status of 200(OK)  (or else you get errors saying that the XML does not yet exist)
  • Flex loads the XML.
  • Voila!

here is a bit of my source code (all the main parts that you’ll need to get your app to work)

<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute”
 backgroundGradientColors=”[#ffffff, #ffffff]“  width=”100%” height=”100%” horizontalAlign=”center”
 verticalAlign=”middle” creationComplete=”init()”  >
 <mx:Script>
  <![CDATA[
    import mx.controls.Alert;
    import mx.rpc.events.FaultEvent;
    import mx.rpc.events.ResultEvent;
    import mx.managers.CursorManager;
    
      private function init():void
      {

as soon as the app loads i set the BusyCursor on ON, so that the user can't click on anything before it's ready for him to click.
      CursorManager.setBusyCursor();

call the function that will send the reuqest to WebFocus (or wherever) for the XML to be created
       HTTPStatusEventExample();      
      }
      
      public function HTTPStatusEventExample():void
         {
         
            var loader:URLLoader = new URLLoader();
            configureListeners(loader);
           
            var request:URLRequest = new URLRequest("http://myurl.com/willcreate/theXML.html");
            try
            {
                loader.load(request);
            } catch (error:Error)
            {
                trace("Unable to load requested document.");
            }           
           
        }
       private function configureListeners(dispatcher:IEventDispatcher):void
       {

there are many many more EventListeners to add here, but all i needed here were these two
            dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
            dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
        }
    

        private function ioErrorHandler(event:IOErrorEvent):void
        {
            trace("ioErrorHandler: " + event);
        }
        private function httpStatusHandler(event:HTTPStatusEvent):void
        {

this will get executed when the status of the requested url is 200 (or complete)
            trace("httpStatusHandler: " + event);
            trace("status: " + event.status);

this is where you acutally send my XML HTTPServices in
      FEX.send();

obviously remove the busy cursor and enable your buttons or whatver else you disables, so the user can click again :)
   CursorManager.removeBusyCursor();     
   btnSubmit.enabled=true;     
   btnHelp.enabled=true;
        }

    your other functions, blah blah blah....
              
                       

  ]]>
 </mx:Script>

<mx:HTTPService id=”FEX” url=”FEX.xml” resultFormat=”e4x”
 result=”quickResultHandler(event);”  fault=”quickFaultHandler(event);”/>

your components and stuff. blah blah blah…   
</mx:Application>

hope this helps!!!

 comments are appreciated :)

Tags: , , , ,

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Copyright © 2007-2012 Cheat Sheet All rights reserved.
Desk Mess Mirrored v1.8.1 theme from BuyNowShop.com.