7 Replies Latest reply on Nov 30, 2008 9:43 PM by cdub

    xml images not displaying

    cdub
      I'm having an issue displaying images from an xml file. It's a portfolio site, so basically it displays text and an image. All the text is working just fine, but for some reason the image (and the whole app) won't display when the image code is added.

      Here's my code:

      <mx:XML id=" portfolioXML"
      source="portfolio.xml" />

      <mx:XMLListCollection id="interActXMLList"
      source="{ portfolioXML.interactive.label}" />

      <mx:List id="interActList"
      dataProvider="{interActXMLList}"
      width="253" height="103" />

      <mx:Number id="selectedWorkIndex">{interActList.selectedIndex}</mx:Number>

      <mx:Text
      id="titleInput"
      text="{ portfolioXML.interactive[selectedWorkIndex].title}"
      width="446" />

      <mx:Text
      id="description"
      text="{ portfolioXML.interactive[selectedWorkIndex].shortDesc}"
      height="101" width="446" />
      <!-- this causes the whole thing to crash
      <mx:Image
      source="{ portfolioXML.interactive[selectedWorkIndex].image}" />
      -->

      xml looks like this:

      <portfolio>
      <interactive>
      <label>The Item</label>
      <title>The Item Title</title>
      <shortDesc>The item is totally awesome.</shortDesc>
      <image> http://www.example.com/images/interactive/item.png</image>
      </interactive>
      </portfolio>

      The url is correct (it works when I hard code it). Anyone know why the images aren't working??
        • 1. Re: xml images not displaying
          -Hob Level 1
          It could be a binding issue. Try deserializing your xml into a value object, and see if that fixes the problem.
          • 2. Re: xml images not displaying
            cdub Level 1
            Do what?? I've never heard of this and my google search only made me even more confused. How is 'deserializing the xml into a value object' done?
            • 3. Re: xml images not displaying
              Level 7

              "cdub" <webforumsuser@macromedia.com> wrote in message
              news:ggsput$816$1@forums.macromedia.com...
              > I'm having an issue displaying images from an xml file. It's a portfolio
              > site,
              > so basically it displays text and an image. All the text is working just
              > fine,
              > but for some reason the image (and the whole app) won't display when the
              > image
              > code is added.
              >
              > Here's my code:
              >
              > <mx:XML id=" portfolioXML"
              > source="portfolio.xml" />
              >
              > <mx:XMLListCollection id="interActXMLList"
              > source="{ portfolioXML.interactive.label}" />
              >
              > <mx:List id="interActList"
              > dataProvider="{interActXMLList}"
              > width="253" height="103" />
              >
              > <mx:Number id="selectedWorkIndex">{interActList.selectedIndex}</mx:Number>
              >
              > <mx:Text
              > id="titleInput"
              > text="{ portfolioXML.interactive[selectedWorkIndex].title}"
              > width="446" />
              >
              > <mx:Text
              > id="description"
              > text="{ portfolioXML.interactive[selectedWorkIndex].shortDesc}"
              > height="101" width="446" />
              > <!-- this causes the whole thing to crash
              > <mx:Image
              > source="{ portfolioXML.interactive[selectedWorkIndex].image}" />
              > -->

              What happens if you use a text object to show the image path above? Does
              that still crash the app?

              Also, try replacing the colon (:) in the XML with its url encoded version
              (&#58;)

              HTH;

              Amy


              • 4. Re: xml images not displaying
                rtalton Level 4
                Quote:
                "The url is correct (it works when I hard code it)."
                Does that mean it does not crash when you hard code it?

                Does your List have an item selected when the app first opens? If not, the image source may be null, causing the error, since it is dependent upon the selectedIndex property (its default is -1).
                • 5. Re: xml images not displaying
                  cdub Level 1
                  Thank you all for getting back to me.

                  Amy: I changed the image path to text and it displayed the url just fine. I tried using &#58; instead of a colon and that displayed at text but not as an image. I even tried wrapping the whole url in cdata tags and that didn't work either.

                  rtalton: It does not crash when it is hard coded. Also, there is a list item selected when the app first opened. I have ' interActList.selectedIndex=0;' in the init function.

                  I'm really at a loss, I never anticipated that I would have so many problems with this, as it seems so basic. Anyone know what's going wrong here?
                  • 6. Re: xml images not displaying
                    rtalton Level 4
                    In my testing, I found the var "selectedWorkIndex" to be the problem. Actually, it is a timing issue as this var is not being set before the image tries to load. I stepped through your code and saw that the image is loading before your number var is being set. Bummer. That causes the error.

                    So you need to write a little Actionscript code to set things up and load the image properly.
                    I created a var for the image control's SOURCE property and I set that var in both the creationComplete handler for the app and a handler for the List's CHANGE event. Voila!

                    • 7. Re: xml images not displaying
                      cdub Level 1
                      NICE!! Thank you.