3 Replies Latest reply on Jun 26, 2006 11:15 AM by Newsgroup_User

    Why can I pass a string, but not a date?

    Level 7
      I have this custom component that at the moment just repeats the passed
      in value. It works if I pass in a string, but if I pass the date I
      actually want it does not work. I can not figure out why.

      dayFormat2 custom component.
      <mx:Script>
      <![CDATA[
      //Define public variables
      public var dayData:String;
      ]]>
      </mx:Script>

      <mx:DateFormatter id="dayNum" formatString="DD" />
      <mx:Label text="{dayData}" />

      -----------------------

      This Works.
      <ns1:dayFormat2 dayData="George" />

      This Does not work.
      <ns1:dayFormat2 dayData="{DayNum.format(dayCells.currentItem.date)}" />

      And neither does this. Of course for this version I change the dayData
      type to date in the custom component.
      <ns1:dayFormat2 dayData="{dayCells.currentItem.date}" />

      Just to make sure that the date exists as I expect. If I replace the
      dayFormat2 custome comment with a label, I get the dates just fine.
      <mx:Label text="{DayNum.format(dayCells.currentItem.date)}" />
        • 1. Re: Why can I pass a string, but not a date?
          Simeon Bateman Level 2
          Well I cant tell you why it works with "george" as the data, but I know that a date that is formated is not a date anymore, its just a string.

          I had this problem a little while back where I was trying to store a formated string as an attribute of my object but it never stored correctly. After asking around I found I had to write a function that could take my formated date string and construct a real date object to be used later.

          Hope that helps put you on the right track.

          simeon
          • 2. Re: Why can I pass a string, but not a date?
            Level 7
            I have tried it both ways, to pass the date itself and a formated string
            of the date, since the hard coded string worked. Neither provides any
            results. I just get a blank screen. No error, just a blank screen.

            Simfluence wrote:
            > Well I cant tell you why it works with "george" as the data, but I know that a
            > date that is formated is not a date anymore, its just a string.
            >
            > I had this problem a little while back where I was trying to store a formated
            > string as an attribute of my object but it never stored correctly. After
            > asking around I found I had to write a function that could take my formated
            > date string and construct a real date object to be used later.
            >
            > Hope that helps put you on the right track.
            >
            > simeon
            >
            >
            • 3. Re: Why can I pass a string, but not a date?
              Level 7
              add the bindable meta in your custom component...seems like that would
              be needed.

              //Define public variables
              [Bindable]
              public var dayData:String;

              Ian Skinner wrote:
              > I have this custom component that at the moment just repeats the passed
              > in value. It works if I pass in a string, but if I pass the date I
              > actually want it does not work. I can not figure out why.
              >
              > dayFormat2 custom component.
              > <mx:Script>
              > <![CDATA[
              > //Define public variables
              > public var dayData:String;
              > ]]>
              > </mx:Script>
              >
              > <mx:DateFormatter id="dayNum" formatString="DD" />
              > <mx:Label text="{dayData}" />
              >
              > -----------------------
              >
              > This Works.
              > <ns1:dayFormat2 dayData="George" />
              >
              > This Does not work.
              > <ns1:dayFormat2 dayData="{DayNum.format(dayCells.currentItem.date)}" />
              >
              > And neither does this. Of course for this version I change the dayData
              > type to date in the custom component.
              > <ns1:dayFormat2 dayData="{dayCells.currentItem.date}" />
              >
              > Just to make sure that the date exists as I expect. If I replace the
              > dayFormat2 custome comment with a label, I get the dates just fine.
              > <mx:Label text="{DayNum.format(dayCells.currentItem.date)}" />