3 Replies Latest reply on Jun 28, 2006 10:21 AM by Newsgroup_User

    Properly binding an object to a custom component.

    Level 7
      I am apparently not doing this. What am I missing to properly bind an
      object from a repeater looping over an array of object to the custom
      component called in the repeater?

      <mx:Repeater
      id="dayCells"
      dataProvider="{days}"
      startingIndex="{weekRows.currentItem}"
      count="7">
      <mx:GridItem
      width="14%"
      borderColor="black"
      borderThickness="1"
      borderStyle="solid">
      <mx:Label
      text="{dayCells.currentItem.formatedDate}" />
      <ian:dayFormat2
      drawData="{dayCells.currentItem as drawDay}"
      test="{dayCells.currentItem.formatedDate}" />
      </mx:GridItem>
      </mx:Repeater>

      {days} is an array of drawDate.as objects returned with a remoteObject.
      I can correctly bind properties of these drawDate objects in the
      lable and the test property of the dayFormat2 customComponent. But I
      can NOT correctly bind the entire object over to dayFormat2. What am I
      missing?

      My current version of dayFormat2.mxml, I have tried several alternatives
      for this file.

      ?xml version="1.0" encoding="utf-8"?>
      <mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml" width="100%">
      <mx:Script>
      <![CDATA[
      import drawDay;

      //Define public variables
      [Bindable]
      public var drawData:drawDay;

      [Bindable]
      public var test:String;
      ]]>
      </mx:Script>

      <mx:DateFormatter id="dayNum" formatString="DD" />

      <mx:HBox
      backgroundColor="0x002649"
      width="100%"
      horizontalAlign="right">
      <mx:Label
      text="{test}"
      color="white" />
      <mx:HBox
      backgroundColor="0xAF1E2D"
      horizontalAlign="center">
      <mx:Label
      text="{dayNum.format(drawData.date)}"
      color="white" />
      </mx:HBox>
      </mx:HBox>

      <mx:Label text="foobar" />
      </mx:VBox>

      The first label bound to the test String works correctly. The second
      label bound to the drawData drawDay object date property does not work
      correctly.

      What is the proper way to bind this object?
        • 1. Re: Properly binding an object to a custom component.
          Level 7
          I have struggled with this all day and made no headway. The only
          strange thing I get is with this line:

          <mx:Label text="{dayCells.currentItem.toString()}" />

          outputs [object Object]

          Not the expected string from this drawDay.as function.

          // toString()
          public function toString():String
          {
          return "Date: " + formatedDate;
          }


          Ian Skinner wrote:
          > I am apparently not doing this. What am I missing to properly bind an
          > object from a repeater looping over an array of object to the custom
          > component called in the repeater?
          >
          > <mx:Repeater
          > id="dayCells"
          > dataProvider="{days}"
          > startingIndex="{weekRows.currentItem}"
          > count="7">
          > <mx:GridItem
          > width="14%"
          > borderColor="black"
          > borderThickness="1"
          > borderStyle="solid">
          > <mx:Label
          > text="{dayCells.currentItem.formatedDate}" />
          > <ian:dayFormat2
          > drawData="{dayCells.currentItem as drawDay}"
          > test="{dayCells.currentItem.formatedDate}" />
          > </mx:GridItem>
          > </mx:Repeater>
          >
          > {days} is an array of drawDate.as objects returned with a remoteObject.
          > I can correctly bind properties of these drawDate objects in the lable
          > and the test property of the dayFormat2 customComponent. But I can NOT
          > correctly bind the entire object over to dayFormat2. What am I missing?
          >
          > My current version of dayFormat2.mxml, I have tried several alternatives
          > for this file.
          >
          > ?xml version="1.0" encoding="utf-8"?>
          > <mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml" width="100%">
          > <mx:Script>
          > <![CDATA[
          > import drawDay;
          >
          > //Define public variables
          > [Bindable]
          > public var drawData:drawDay;
          >
          > [Bindable]
          > public var test:String;
          > ]]>
          > </mx:Script>
          >
          > <mx:DateFormatter id="dayNum" formatString="DD" />
          >
          > <mx:HBox
          > backgroundColor="0x002649"
          > width="100%"
          > horizontalAlign="right">
          > <mx:Label
          > text="{test}"
          > color="white" />
          > <mx:HBox
          > backgroundColor="0xAF1E2D"
          > horizontalAlign="center">
          > <mx:Label
          > text="{dayNum.format(drawData.date)}"
          > color="white" />
          > </mx:HBox>
          > </mx:HBox>
          >
          > <mx:Label text="foobar" />
          > </mx:VBox>
          >
          > The first label bound to the test String works correctly. The second
          > label bound to the drawData drawDay object date property does not work
          > correctly.
          >
          > What is the proper way to bind this object?
          • 2. Re: Properly binding an object to a custom component.
            ntsiii Level 3
            I see nothing obviously wrong. T he [object Object] is happening because you are trying to display a complex object as a string. The item can't really be represented as a string. Try looking at a specific property instead.

            Tracy
            • 3. Re: Properly binding an object to a custom component.
              Level 7
              ntsiii wrote:
              > I see nothing obviously wrong. T he [object Object] is happening because you
              > are trying to display a complex object as a string. The item can't really be
              > represented as a string. Try looking at a specific property instead.
              >
              > Tracy
              >

              Yes I could output individual properties just fine. I was having
              trouble moving the object around. See my Object type Coercion error for
              a follow up to this issue.