3 Replies Latest reply on May 14, 2009 8:37 AM by eddyys

    First Time to Flex


      Hi guys, I am very new to flex and bought a book to help me. "The Flex Bible".  Anyways, I have been working on an app to select an item from a list object and then it would display a data grid with the id of the xml list selected item.  Here is the code.


                import mx.rpc.*;
              public var listLoad:HTTPService;
                public function loadListData(event:Event):void {
                  listLoad = new HTTPService();
                  listLoad.url = "http://localhost/xml/" + List(event.target).selectedItem.@id + ".xml";
                  listLoad.resultFormat = "e4x";
           <mx:HTTPService id="em" url="http://localhost/xml/emailList.xml" resultFormat="e4x"/>
           <mx:TabNavigator id="tn" width="100%" height="100%" paddingBottom="10" paddingLeft="10" paddingTop="10" paddingRight="10">
               <mx:VBox label="Manage">
                    <!-- Display the email list tree -->
                    <mx:HDividedBox width="100%" height="100%">
                         <mx:List id="manageTree" width="200" height="100%" labelField="@name" dataProvider="{em.lastResult.item}"
                         <mx:DataGrid dataProvider="listLoad" />

      And the XML files look like this,



      <item name="Email Lists">
           <item id="1" name="Website" />          
           <item id="2" name="Advertise" />






      As you can se from above it is some pretty simple XML.  I really am unclear about what i am doing wrong and how i can dynamically load xml files via action scipt with HTTPService class.


      Any help would be awesome!




        • 1. Re: First Time to Flex
          BennyBeta Level 4

          One problem, it doesn't look like you have a result handler for your HTTPService call.


             <mx:HTTPService id="httpInMXML" url="http://www.flexafterdark.com"
                method="GET" resultFormat="text"
                result="resultHandler(event)" fault="faultHandler(event)"


             var http:HTTPService = new HTTPService();
             // register event handlers (resultHandler and faultHandler functions)
             http.addEventListener( ResultEvent.RESULT, resultHandler );
             http.addEventListener( FaultEvent.FAULT, faultHandler );
             // specify the url to request, the method and result format
             http.url = "http://www.flexafterdark.com";
             http.method = "GET";
             http.resultFormat = "text";
             // send the request

          The following documentation may be helpful too:



          I hope that helps...


          Ben Edwards

          1 person found this helpful
          • 2. Re: First Time to Flex
            BennyBeta Level 4

            Oh, and here is what result handler and fault handler functions may look like:


               public function resultHandler( event:ResultEvent ):void
                  Alert.show( "RESULT: "+ event.result as XML );
               public function faultHandler( event:FaultEvent ):void
                  Alert.show( "FAULT: " + event.fault.message );

            Which I got from here:



            I hope that helps...


            Ben Edwards

            • 3. Re: First Time to Flex
              eddyys Level 1

              Thanks for the quick response, as you can see i do not know what the ID of the XML file will be.  And that first part helped me and tanks.  As for implementing the data into the dat grid, how would i go upon doing that?