3 Replies Latest reply on Mar 12, 2010 6:33 PM by David_F57

    xml problems

    MrSchieska

      well this is my first try with flash builder 4 so it would likley be a dumb mistake XD

       

      this is my xml:
      <?xml version="1.0" encoding="utf-8"?>
      <entry>
         <title>TEST</title>
         <id>0000001</id>
         <img1>http://www.imagemagick.org/Magick%2B%2B/thumbnail-anatomy-plain.jpg</img1>
         <date day="01" month="januari" year="2010" />
         <summary>lalalalala </summary>
         <client> client 1 </client>
         <linkentry label="text" href="http://www.google.nl"/>
      </entry>

       

      and this my main.mxml:
      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                  xmlns:s="library://ns.adobe.com/flex/spark"
                  xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="1024" minHeight="768"
                  creationComplete="service.send()">

         <fx:Script>
            <![CDATA[
               import mx.collections.ArrayCollection;
               import mx.rpc.events.ResultEvent;

               [bindable]
               private var ac:ArrayCollection;
               private function service_resultHandler(event:ResultEvent):void{
                  ac = event.result.entry;
               }

            ]]>
         </fx:Script>
            <fx:Declarations>
               <s:HTTPService id="service" url="http://schieska.comlu.com/test.xml" result="service_resultHandler(event)" />
            </fx:Declarations>
         <mx:Image x="154" y="152" width="166" height="187" source="{img1}" />
         <mx:Text text="{title}" x="207" y="95" />
      </s:Application>

       

      when I run it i get 2 errors:
      Description   Resource   Path   Location   Type
      1120: Access of undefined property img1.   xmltest.mxml   xmltest/src   line 24   Flex Problem
      1120: Access of undefined property title.   xmltest.mxml   xmltest/src   line 25   Flex Problem

       

      what am i doing wrong?

       

      greetz Schieska

        • 1. Re: xml problems
          David_F57 Level 5

          Hi,

           

          Your first problem is that img1 and title don't exist until after you have loaded the xml file, you can't populate your image or text components until you have retrieved the data.

           

          So after the xml is retrieved you can populate the text field(in the result handler), Then you need to retrieve the image with a url loader so that you can populate the image component. By simply giving the image name to the image component will result in the component recieving no content so the correct process is to get the data for the image once you have that data pass it to the image component.

           

           

          David.

          1 person found this helpful
          • 2. Re: xml problems
            MrSchieska Level 1

            Hi,

             

            I think that I know what you mean, but I can't seem to get it to work.

            could you please give me an example of how I could do this.

             

            Schieska

            • 3. Re: xml problems
              David_F57 Level 5

              Hi,

               

              The following example is similar to what you want, the difference is that it loops through the xml once it has retrieved it and downloads the images into an array.

               

              I have enabled source view (right click on the swf to get its source code)

               

               

              http://gumbo.flashhub.net/fader/

               

               

              Just a note this was done using an updated sdk (dec' 09) so it would be better to get a recent/nightly build of the flex 4 sdk if you want to copy the project into your Flashbuilder IDE.

               

               

              David