1 Reply Latest reply on Dec 11, 2007 10:04 AM by ntsiii

    Cant get arraycollection to work

    NicholasKoji
      im not sure what is going wrong here but this script takes the dates giving from the said XML file and places them into an array then into an array collection so that it can flip those dates to disable the dates i do not want.

      im not sure what is wrong with this script though......

      quote:


      <?xml version="1.0" encoding="iso-8859-1"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="getAvailability.send()">


      <mx:HTTPService
      id="getAvailability"
      url=" http://www.allaboutthekick.com/flex/php/dates.xml"
      method="post"
      resultFormat="e4x"
      result="dateHandler(event)"
      showBusyCursor="true"
      useProxy="false">
      </mx:HTTPService>

      <mx:Script>
      <![CDATA[

      import mx.collections.ArrayCollection;
      import mx.rpc.events.ResultEvent;

      [Bindable]
      private var validDates:ArrayCollection;

      private function dateHandler(event:ResultEvent):void{
      var dateArray:Array = new Array();
      for each (var p:XML in event.result..day){
      var date:Date = new Date(p.@year,p.@month,p.@day);
      dateArray.push(date)
      }
      validDates = new ArrayCollection(dateArray);
      }




      private function setValidDates(validDates:ArrayCollection):void{
      var rangeArray:Array = new Array;
      var millisecondsPerDay:int = 1000 * 60 * 60 * 24;
      for(var i:Number = 0; i < validDates.length; i++){
      var startIndex:Number;
      if (i > 0){
      startIndex = (i-1);
      } else {
      startIndex = i
      }
      var startDate:Date = new Date(validDates[startIndex].getTime() + (1* millisecondsPerDay));
      var endDate:Date = new Date(validDates .getTime() - (1 * millisecondsPerDay));
      if(i == 0){ rangeArray.push({rangeStart:new Date("Jan 1 1906"),rangeEnd:new Date(endDate)});
      } else if(i != validDates.length && i != 0){
      rangeArray.push({rangeStart:new Date(startDate),rangeEnd:new Date(endDate)});
      }
      }
      startDate = new Date(endDate.getTime() + (2*millisecondsPerDay));
      rangeArray.push({rangeStart:new Date(startDate)});
      myCal.disabledRanges = rangeArray;
      }

      ]]>
      </mx:Script>
      <mx:DateChooser id="myCal"/>

      </mx:Application>