3 Replies Latest reply on Aug 20, 2009 3:23 AM by kkc_mca

    Problem in external XML reading

    keenkiran

      Hi,

      I am trying to develop a birthday application.The aim of the application is to populate all the birthday dates in datechooser and display the appropriate photograph of the person when the highlighted date is clicked.

      When I am trying to access {xImages.img[i].BirthDate.toString()} value, it is giving an error : Error #1009: Cannot access a property or method of a null object reference

      The following is the code:

       

      Birthday Application


      <mx:Script>
              <![CDATA[
                  import mx.rpc.events.ResultEvent;
                 public var mySource:String="assets/birthday/pictures/1.jpg"
                 [bindable]private var xImages:XML
         private function init():void {
                      imageData.send();
                      dc1.displayedMonth = 2;
                      dc1.displayedYear = 2009;
                  }          
                 
          public function displayDates():void {
                      var dateRanges:Array = [];
                      for (var i:int=0; i<shows.show.length(); i++) {
                          var cDate:Date =
                              new Date(xImages.img[i].BirthDate.toString());          
                          var cDateObject:Object =
                              {rangeStart:cDate, rangeEnd:cDate};
                          dateRanges.push(cDateObject);
                      }
                      dc1.selectedRanges = dateRanges;
                  }

          function setPath(myPath:String):void
                  {
                      mainImage.source=myPath;
                  } 
                  function resultHandler(event:ResultEvent):void
                  {
                      xImages = event.result as XML
                      trace (xImages.toXMLString());
                  }       
              ]]>
          </mx:Script>   
         
      <mx:HTTPService id="imageData" url="assets/birthday/images.xml" resultFormat="e4x" result="resultHandler(event)"/>
      <mx:VDividedBox width="20%" height="100%">
          <mx:Panel height="68%" width="100%">
               <mx:DateChooser id="dc1"
              showToday="false"
              creationComplete="displayDates()"
          />   
          </mx:Panel>
          <mx:Panel height="100%" width="100%">
              <mx:Text text="this is for birthday pics"/>
          </mx:Panel>
      </mx:VDividedBox>
      <mx:Panel width="80%" height="100%">
      <mx:VDividedBox width="100%" height="100%">
          <mx:Canvas height="100%" width="100%">
         
             <mx:Image id="mainImage" source="{mySource}" width="80%" height="80%" verticalCenter="0" horizontalCenter="0" />
             
          </mx:Canvas>
          <mx:HBox height="20%" width="50%" horizontalScrollPolicy="on" verticalCenter="0">
              <mx:Repeater id="imageRepeater" dataProvider="{imageData.lastResult.img}">
                  <mx:Canvas width="55" height="55" backgroundColor="#000000" horizontalScrollPolicy="off" verticalScrollPolicy="off" borderStyle="solid">
                      <custom:CustomImage path="{imageRepeater.currentItem.src}" width="89" height="100%" useHandCursor="true" buttonMode="true" source="{imageRepeater.currentItem.thumbnail}" verticalCenter="0" left="0" click="setPath(String(event.currentTarget.path));"/>
                  </mx:Canvas>
              </mx:Repeater>
          </mx:HBox>
      </mx:VDividedBox>   
      </mx:Panel>

      </mx:Application>

       

      Example of XML file is as follows:

      images.xml

      <gallery>

      <img>
      <src>assets/birthday/pictures/1.jpg
      </src> 
      <thumbnail>assets/birthday/pictures/t1.gif
      </thumbnail>
      <BirthDate>02/28/2009</BirthDate>
      <title>""</title>
      <caption>""</caption>
      </img>

      <img>
      <src>assets/birthday/pictures/2.jpg
      </src> 
      <thumbnail>assets/birthday/pictures/t2.gif</thumbnail>
      <BirthDate>02/12/2009</BirthDate>
      <title>""</title>
      <caption>""</caption>
      </img>

      <img>
      <src>assets/birthday/pictures/3.jpg
      </src> 
      <thumbnail>assets/birthday/pictures/t3.gif
      </thumbnail>
      <BirthDate>02/16/2009</BirthDate>
      <title>""</title>
      <caption>""</caption>
      </img>

       

      </gallery>

      Can anybody correct me where I am doing a mistake. I am not able to figure out and is blocked here

      Please help me

      Thank you in advace,

       

       

      Cheers,

      KK