4 Replies Latest reply on Mar 5, 2008 8:11 PM by MPetroDesigns

    XML problem

      Hi Guys,

      We have an assignment in our Flex class to build a mini website showcase. The website must have 3 links at the top, which in my case are Photography, Automotive, and Personal/Portfolio. The website must pull data from an XML file. Basically the way I set it up is in 3 states, where base is photography, etc. I am also using the "repeater" function to load in all of the img's from the XML.

      I've figured out abut 85% of it but am faced with a problem which I can't seem to address.

      When the user clicks on Automotive, or Personal/Portfolio, I only want a section of the XML file to be loaded.

      This is the code I'm using to pull from the XML

      <mx:Repeater id="myRepeater" dataProvider="{myXML.lastResult.gallery.photography}">
      <mx:HBox width="100" height="95" horizontalAlign="center" verticalAlign="middle" verticalScrollPolicy="off" horizontalScrollPolicy="off">
      <mx:Image width="80" height="80" completeEffect="bigFade" source="{myRepeater.currentItem.img}" rollOverEffect="myZoom" rollOutEffect="myZoomOut" click="getImage(event)"/>

      I've tried making an If statement saying
      if( currentState=='automotive' ){

      But that didn't work..

      Any ideas? I can send who ever the .zip file and/or post the current app online so you can see it visually if that helps.

      Mike Petro
        • 1. Re: XML problem
          ntsiii Level 3
          Do not bind directly to lastResult. There are many reasons and this is one.

          Instead, use a result handler function. In that function, use an e4x expression to get the nodes you want, then assign that XMLList to the Repeater's dataProvider.

          • 2. Re: XML problem
            MPetroDesigns Level 1
            I'm pretty new to Flex, and have no idea what an e4 expression is. Can you go into a bit more detail and/or give me an example of what mine will look like? Thanks again.
            • 3. Re: XML problem
              ntsiii Level 3
              This, "lastResult.gallery.automotive" is an e4x expression. An "e4x expression" is just the way you specify a node list in AS3's XML class.

              How are you getting your data? HTTPService? Can you set up a result handler?

              when I get to my other machine I will post some example code.


              • 4. Re: XML problem
                MPetroDesigns Level 1
                Oh, gotcha.

                Yeah I'm using HTTPService

                <mx:HTTPService id="myXML" url="../assets/pictures/pictures.xml"/>

                If you want, I can send you the .zip to your email?