3 Replies Latest reply on Mar 11, 2008 6:05 AM by vzwhaley

    DateChooser and Error 1009

    vzwhaley
      Could anyone give me some suggestions on why the following code throws an "Error 1009: Cannot Access a property or method of a null object reference" when the user clicks on a date in the DateChooser? Thanks for any suggestions.

      "Attach Code"
      <?xml version="1.0" encoding="utf-8"?>
      <!-- controls\date\DateChooserEvent.mxml -->
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" width="100%" height="100%" borderStyle="none" borderThickness="2"
      layout="absolute" horizontalAlign="left" verticalAlign="top" backgroundGradientColors="[#666666, #ffffff]" creationComplete="currentDate.send();">

      <mx:Script>

      <![CDATA[

      import mx.rpc.events.ResultEvent;
      import mx.controls.Text;
      import mx.events.CalendarLayoutChangeEvent;
      import mx.collections.XMLListCollection;


      [Bindable]

      private var sectionList:XMLList;

      private function buildListHandler(event:ResultEvent):void
      {
      sectionList = event.result..pubDate;

      }

      private function useDate(eventObj:CalendarLayoutChangeEvent):void
      {
      // Make sure selectedDate is not null.
      if (eventObj.currentTarget.selectedDate == null) {
      return
      } else {
      userRequest.send();
      }

      //Access the Date object from the event object.
      var day:Text;
      var date:Text;
      var month:Text;
      var year:Text;
      var wholeDate:Text;
      day.text=eventObj.currentTarget.selectedDate.getDay();
      date.text=eventObj.currentTarget.selectedDate.getDate();
      month.text=eventObj.currentTarget.selectedDate.getMonth();
      year.text=eventObj.currentTarget.selectedDate.getFullYear();
      wholeDate.text=eventObj.currentTarget.selectedDate.getFullYear()+"/"+(eventObj.currentTar get.selectedDate.getMonth()+1)+"/"+eventObj.currentTarget.selectedDate.getDate();
      }

      private function onUserRequestResult(e:Event) :void
      {
      buildList.send();
      }


      ]]>
      </mx:Script>

      <mx:DateFormatter id="df" formatString="YYYY_MM_DD"/>

      <mx:DateFormatter id="df2" formatString="EEEE, MMMM DD, YYYY"/>

      <mx:DateChooser id="dateChooser" change="useDate(event)" showToday="true" x="220" y="101" cornerRadius="14" yearNavigationEnabled="true"
      disabledRanges="{[ {rangeEnd: new Date(2006, 4, 0)} ]}"/>

      <mx:HTTPService id="currentDate" url="Sections_XML.php?Date={df.format(new Date())}"
      showBusyCursor="true" result="buildListHandler(event)" resultFormat="e4x"></mx:HTTPService>

      <mx:HTTPService id="userRequest" result="onUserRequestResult(event)" url="Sections_XML.php?Date={df.format(dateChooser.selectedDate)}"
      showBusyCursor="true" useProxy="false" method="POST"></mx:HTTPService>

      <mx:HTTPService id="buildList" url="Tearsheets.xml" showBusyCursor="true" result="buildListHandler(event)" resultFormat="e4x"/>

      <!-- Effects -->

      <mx:Fade id="fadeIn" duration="3000" alphaFrom="0" alphaTo="1"/>
      <mx:Fade id="fadeOut" duration="3000" alphaFrom="1" alphaTo="0"/>

      <!-- User Interface -->
      <mx:Panel id="tearsheetsViewPanel" title="Tearsheets Preview" width="100%" height="100%" x="408" y="10">

      <mx:Tile id="Tile" width="100%" height="100%">
      <mx:Repeater id="photos" dataProvider="{sectionList.section.page}">
      <mx:VBox
      xmlns:mx=" http://www.adobe.com/2006/mxml"
      horizontalAlign="center"
      >
      <mx:Image
      id="myImage"
      source="{photos.currentItem.@image}"
      buttonMode = "true"
      completeEffect="{fadeIn}"
      click="navigateToURL(new URLRequest(event.currentTarget.getRepeaterItem().@pdf), '_blank');"
      />
      </mx:VBox>
      </mx:Repeater>
      </mx:Tile>

      </mx:Panel>

      </mx:Application>
        • 1. Re: DateChooser and Error 1009
          Gregory Lafrance Level 6
          Can you post the data this app relies on, perhaps as XML?
          • 2. Re: DateChooser and Error 1009
            vzwhaley Level 1
            This is an example of the XML file:

            <tearsheets>
            <pubDate aname="Monday, March 10, 2008">
            <section aname="A">
            <page aname="02" date="20080310" sectionID="A" image="tearsheets/2008/03/10/jpg/20080310_A_02.jpg" pdf="tearsheets/2008/03/10/pdf/20080310_A_02.pdf"/>
            <page aname="03" date="20080310" sectionID="A" image="tearsheets/2008/03/10/jpg/20080310_A_03.jpg" pdf="tearsheets/2008/03/10/pdf/20080310_A_03.pdf"/>
            </section>
            </pubDate>
            </tearsheets>
            • 3. Re: DateChooser and Error 1009
              vzwhaley Level 1
              I fixed the problem by rearranging the position of the calendar variables:

              private function useDate(eventObj:CalendarLayoutChangeEvent):void
              {
              // Make sure selectedDate is not null.
              if (eventObj.currentTarget.selectedDate == null) {
              //Access the Date object from the event object.
              var day:Text;
              var date:Text;
              var month:Text;
              var year:Text;
              var wholeDate:Text;
              day.text=eventObj.currentTarget.selectedDate.getDay();
              date.text=eventObj.currentTarget.selectedDate.getDate();
              month.text=eventObj.currentTarget.selectedDate.getMonth();
              year.text=eventObj.currentTarget.selectedDate.getFullYear();
              wholeDate.text=eventObj.currentTarget.selectedDate.getFullYear()+"/"+(eventObj.currentTar get.selectedDate.getMonth()+1)+"/"+eventObj.currentTarget.selectedDate.getDate();
              } else {
              userRequest.send();
              }
              }

              Thanks for the help!