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

    First Time to Flex

    eddyys

      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.

       

      <mx:Script>
               <![CDATA[
                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";
                  listLoad.send();
               }
      
              ]]>
          </mx:Script>
      
           <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}"
                               click="loadListData(event);"/>
                         <mx:DataGrid dataProvider="listLoad" />
                    </mx:HDividedBox>
               </mx:VBox>
          </mx:TabNavigator>
      

      And the XML files look like this,

       

      emailList.xml

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

      1.xml

      <list>
           <item>
                <firstName>Dude</firstname>
                <lastName>Nukem</lastname> 
                <email>dude@gmail.com</email>
                <phone>8885554444</phone>
           </item>
      </lit>
      

      2.xml

      <list>
           <item>
                <firstName>John</firstname>
                <lastName>Doe</lastname> 
                <email>john@gmail.com</email>
                <phone>8005551111</phone>
           </item>
      </list>
      

       

      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!

       

      Thanks,

      Eddyys

        • 1. Re: First Time to Flex
          BennyBeta

          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)"
             />

          OR...

             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
             http.send();

          The following documentation may be helpful too:

          http://www.flexafterdark.com/docs/Flex-HttpService

           

          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:

            http://www.flexafterdark.com/docs/ActionScript-Responder

             

            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?

               

              Thanks.