5 Replies Latest reply on Sep 12, 2007 6:30 AM by T.Croft

    xml attribute issue

    dajj123
      Hi All
      I have been trying to build a little app. I have most of it working. A drop down menu is populated from a xml. User selects option then a second menu is populated from a new xml wich is retrived based on the users selection. I have pretty much working both xml files load. The first works great. The second load once the use makes their selection. The problem I am having is the second uses attributes that need to populate the second drop down box. I can trace the attribute so I know the xml loaded and I am able to access the attribute. I am not able to however populate the drop down with that attribute.

      Here is the code any help would be great.

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" initialize="initializeHandler(event)">
      <mx:Script>
      <![CDATA[
      import mx.rpc.events.ResultEvent;
      import mx.collections.XMLListCollection;
      [Bindable] public var statesList:XMLListCollection;
      private function initializeHandler(event:Event):void{

      countriesService.send();
      }

      private function changeHandler(event:Event):void{

      stateService.resultFormat = "xml";
      stateService.addEventListener(ResultEvent.RESULT, handleResult);
      stateService.send();

      }
      private function handleResult(event:ResultEvent):void
      {

      var _xml:XML = new XML(event.result);

      var states:XMLList = new XMLList(_xml.state);
      statesList = new XMLListCollection(states);

      trace('_xml.state.@ab.toString() = '+_xml.state.@ab.toString()) ;
      trace("ASDF"+_xml.state.@ab.toString())
      }
      ]]>
      </mx:Script>
      <mx:HTTPService id="countriesService" url=" http://www.necrum.com/boeing/techPass/country.xml" />
      <mx:HTTPService id="stateService" url=" http://www.necrum.com/boeing/techPass/state.xml" > <mx:request>
      <country>
      {country.value}
      </country>
      </mx:request>
      </mx:HTTPService>
      <mx:VBox x="54" y="76" width="174" height="118">
      </mx:VBox>
      <mx:ComboBox id="country" dataProvider="{countriesService.lastResult.countries.country}" change="changeHandler(event)" x="322" y="108" width="143"/>
      <mx:ComboBox id="state" dataProvider="{stateService.lastResult.state}" labelField="@ab" x="322" y="136" width="143"/>
      </mx:Application>


        • 1. Re: xml attribute issue
          chris.huston.t10 Level 3
          Try setting the resultFormat of your stateService to "e4x". This is the NEW xml format that is much improved.

          Also, set the comboBox's dataProvider in your result function rather than binding on the service.lastResult property which is quite hard to debug.

          state.dataProvider = event.result.state;
          OR
          state.dataProvider = statesList;

          Vygo
          • 2. Re: xml attribute issue
            dajj123 Level 1
            thanx how do I set the stateService to "e4x"
            • 3. Re: xml attribute issue
              chris.huston.t10 Level 3
              Just change this line of code:

              stateService.resultFormat = "xml";
              to
              stateService.resultFormat = "e4x";

              Or you can se this directly in your mxml:

              <mx:HTTPService id="stateService" url=" http://www.necrum.com/boeing/techPass/state.xml" resultFormat="e4x" > <mx:request>
              <country>
              {country.value}
              </country>
              </mx:request>
              </mx:HTTPService>


              Vygo
              • 4. Re: xml attribute issue
                dajj123 Level 1
                thank you so much. that worked.
                • 5. Re: xml attribute issue
                  T.Croft
                  I've tried the following application, and cannot access the attribute text for the condition tag. I've tried e4x and xml resultFormats. I've also tried creating an XML object from the lastResult without success. Any help is appreciated.

                  <?xml version="1.0"?>
                  <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
                  creationComplete="weatherRequest.send()" layout="absolute">

                  <mx:Script>
                  <![CDATA[
                  public function updateWeather(event:Event):void {
                  var hString:String=weatherRequest.lastResult.rss.channel.item.description;
                  var id1:int=hString.indexOf("http:");
                  var id2:int=hString.indexOf(".gif")+4;
                  weatherIcon.source = hString.substring(id1,id2);

                  weatherText.text = weatherRequest.lastResult.rss.channel.item.condition.@text;
                  }
                  ]]>
                  </mx:Script>
                  <mx:HTTPService id="weatherRequest" url=" http://weather.yahooapis.com/forecastrss?p=07920" result="updateWeather(event)"/>


                  <mx:Panel width="250" height="120" layout="absolute" title="Weather">
                  <mx:HBox>
                  <mx:Image id="weatherIcon" height="52" width="52" source=""/>
                  <mx:Text id="weatherText"/>
                  </mx:HBox>
                  </mx:Panel>

                  </mx:Application>