4 Replies Latest reply on Oct 2, 2006 12:14 AM by yoyesman

    Use HTTPService to repeat component item

      Hi,
      first I would like to create a list of item from a HTTPService.

      Here the XML file at the HTTPservice's url :
      <?xml version="1.0" encoding="ISO-8859-1"?>
      <artistelist>
      <artiste id="0" nom="Tous les artistes"></artiste>
      <artiste id="3" nom="Chemical Brother"></artiste>
      <artiste id="1" nom="Noir Désir"></artiste>
      <artiste id="2" nom="U2"></artiste>
      </artistelist>

      and here a part of my mxml component :

      <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" width="514" height="300" xmlns:local="*" creationComplete="GetArtiste.send();">
      <mx:HTTPService id="GetArtiste" url=" http://127.0.0.1/tunes/bin/music.php?gettype=artiste" resultFormat="e4x" useProxy="false"/>
      <mx:Repeater id="r" dataProvider="{GetArtiste.lastResult}">
      <mx:RadioButton id="Radio" label="{r.currentItem.artistelist.artiste.nom}" x="{r.currentIndex}" width="150"/>
      </mx:Repeater>
      </mx:Canvas>

      With this, I have only 1 radio button and no label ! I tried to change the dataProvider of the repeater by GetArtiste.lastResult.artistelist, and I have no radio button.

      I think there is something missing but I can't find what. I've read some post and tried a lot of things but with no results... Does anyone see what's wrong ?

      The second part of my problem is to display an mxml component instead of the radio button. And my question is : what about if my component resize his height (by changing his state)? Are the other components in my list going adapting their positions ?

      Thanks a lot for your help

      Mika
        • 1. Re: Use HTTPService to repeat component item
          peterent Level 2
          I think the problem is how you are addressing the XML. GetArtiste.lastResult is <artistelist> node. So I believe you want the Repeater's dataProvider to be: dataProvider="{GetArtiste.lastResult.artiste}" which names the repeated element directly below the root node.

          Now your RadioButton label can be: label="{r.currentItem.@nom}" where you use @nom because nom is an attribute of the <artiste> node.

          Instead of putting your RadioButtons inside of a Canvas, make it a VBox - this way they won't overlap each other (which they will with x="{r.currentIndex}"). And because they will be inside of a VBox, any size changes should work correctly.
          • 2. Re: Use HTTPService to repeat component item
            Level 1
            Great ! that's working perfectly... Thanks again for your help Peterent !

            Just now, I replace the radio button by a component. And I would like to assign it a dataProvider that is the r.currentItem itself. I don't find the way to assign an ArrayCollection that representing the r.currentItem.

            Here what I do for each property to set :

            <mx:Repeater id="r" dataProvider="{GetVin.lastResult.vin}">
            <local:vin width="520" id="vin1" description="{r.currentItem.@description}"/>
            </mx:Repeater>

            And in my 'vin' component add a code like this :

            [Bindable]
            private var descrip:String;

            public function set description(desc:String):void {
            descrip = desc;
            }

            It's working but, I think there will be a simple way to do this for many properties to set... If anyone have an idea ?
            Thanks for your help.

            Mika
            • 3. Re: Use HTTPService to repeat component item
              peterent Level 2
              You already see how to set a single item (your function set description). If you want to set more properties, create a set function that accepts one of the XML nodes and set all the properties that way:

              function set all (item:XML) : void
              {
              description = item.@description;
              // etc.
              }

              Then: <local:vin width="520" all="{XML(r.currentItem)}"/>
              • 4. Re: Use HTTPService to repeat component item
                Level 1
                Thanks a lot for your help. I will test that.