7 Replies Latest reply on Aug 13, 2008 5:42 AM by Noreaster76

    Newbie Help Needed: Data Binding

    Noreaster76
      Okay, lemme see if I can possibly explain this issue clearly enough... (The whole explanation of the object graph may very well be superfluous, so you can probably skip to the bottom.)

      I have a whole object graph that I've downloaded from my server to my Flex client. Here's the general gist of object relationships (and I have to lay it out this way because there's not really any way to sketch on a whiteboard the object graph):

      Object A is a parent of object B, and there is a one-to-many relationship between the two. That is, there is one A to many B's.
      There is a one-to-one relationship between Object B and Object C.
      There is a many-to-one relationship between Object C and Object D. That is, there are many C's to one D.
      There is a many-to-one relationship between Object D and Object E. That is, there are many D's to one E.
      There is a many-to-one relationship between Object E and Object F. That is, there are many E's to one F.

      Now, because I am only given information from the user as far as which object A is the chosen object (that is, I'm not told right off the bat which B's, C's, D's, E's, and F's to pull from the server), I have a series of events being fired and listened to, so the sequence of steps pretty much goes like this:

      User chooses a particular object A.
      I pull A from the server.
      I pull all of A's children (the B objects).
      I look at the keys stored in the B's and pull the corresponding C's.
      I look at the keys stored in the C's and pull their parents, the D's.
      I look at the keys stored in the D's and pull their parents, the E's.
      I look at the keys stored in the E's and pull their parents, the F's.

      Now, here's where I'm having an issue:
      The B objects store a Date object called startTime. The D objects store an integer called runTimeMillis (the runtime of the video, in milliseconds). I need to somehow present endTime, which is simply the sum of startTime + runTimeMillis. But I have to do it in a data binding because the D objects are downloaded later than the B objects. But I've tried so many different ways of coding it, and nothing seems to work. Here's where I'm at:

      <mx:DateFormatter id="hmmssaFormatter" formatString="L:NN:SSA"/>
      ...
      <mx:Label text="{hmmssaFormatter.format(B.startTime + B.C.D.runTimeMillis)}" fontWeight="bold"/>


      The only thing I get in my client is a blank label. What am I doing wrong? The following seems to work just fine in displaying the start time of the video:

      <mx:Label text="{hmmssaFormatter.format(B.startTime)}" fontWeight="bold"/>

      But adding a number of milliseconds doesn't seem to work at all. Can anyone shed some light on the matter? Thanks!
        • 1. Re: Newbie Help Needed: Data Binding
          Level 7

          "Noreaster76" <webforumsuser@macromedia.com> wrote in message
          news:g7qa7e$b3i$1@forums.macromedia.com...
          > Okay, lemme see if I can possibly explain this issue clearly enough...
          > (The
          > whole explanation of the object graph may very well be superfluous, so you
          > can
          > probably skip to the bottom.)
          >
          > I have a whole object graph that I've downloaded from my server to my Flex
          > client. Here's the general gist of object relationships (and I have to
          > lay it
          > out this way because there's not really any way to sketch on a whiteboard
          > the
          > object graph):
          >

          > Object A is a parent of object B, and there is a one-to-many relationship
          > between the two. That is, there is one A to many B's.
          > There is a one-to-one relationship between Object B and Object C.
          > There is a many-to-one relationship between Object C and Object D. That
          > is,
          > there are many C's to one D.
          > There is a many-to-one relationship between Object D and Object E. That
          > is,
          > there are many D's to one E.
          > There is a many-to-one relationship between Object E and Object F. That
          > is,
          > there are many E's to one F.
          >

          > Now, because I am only given information from the user as far as which
          > object
          > A is the chosen object (that is, I'm not told right off the bat which B's,
          > C's,
          > D's, E's, and F's to pull from the server), I have a series of events
          > being
          > fired and listened to, so the sequence of steps pretty much goes like
          > this:
          >

          > User chooses a particular object A.
          > I pull A from the server.
          > I pull all of A's children (the B objects).
          > I look at the keys stored in the B's and pull the corresponding C's.
          > I look at the keys stored in the C's and pull their parents, the D's.
          > I look at the keys stored in the D's and pull their parents, the E's.
          > I look at the keys stored in the E's and pull their parents, the F's.
          >

          > Now, here's where I'm having an issue:
          > The B objects store a Date object called startTime. The D objects store an
          > integer called runTimeMillis (the runtime of the video, in milliseconds).
          > I
          > need to somehow present endTime, which is simply the sum of startTime +
          > runTimeMillis. But I have to do it in a data binding because the D
          > objects are
          > downloaded later than the B objects. But I've tried so many different
          > ways of
          > coding it, and nothing seems to work. Here's where I'm at:
          >
          > <mx:DateFormatter id="hmmssaFormatter" formatString="L:NN:SSA"/>
          > ...
          > <mx:Label text="{hmmssaFormatter.format(B.startTime +
          > B.C.D.runTimeMillis)}"
          > fontWeight="bold"/>
          >
          >
          > The only thing I get in my client is a blank label. What am I doing
          > wrong?
          > The following seems to work just fine in displaying the start time of the
          > video:
          >
          > <mx:Label text="{hmmssaFormatter.format(B.startTime)}" fontWeight="bold"/>
          >
          > But adding a number of milliseconds doesn't seem to work at all. Can
          > anyone
          > shed some light on the matter? Thanks!

          What type of objects are B's and D's? Are you sure you actually have date
          objects in hand to work with? Where is this label? If there are many D's
          to one B, then you can't just have one label that will be able to display
          all the values.


          • 2. Re: Newbie Help Needed: Data Binding
            Noreaster76 Level 1
            quote:

            What type of objects are B's and D's?


            All the objects are user-defined objects (meaning, model objects that I have defined, each in their own ActionScript files).

            quote:

            Are you sure you actually have date objects in hand to work with?


            Yes, because the following works just fine:

            <mx:Label text="{hmmssaFormatter.format(B.startTime)}" fontWeight="bold"/>

            In addition, I've displayed the value in the D.runTimeMillis, and that seems to contain a value as well. I'm just having trouble adding them together and displaying the result in an HH:MM:SS format.

            quote:

            Where is this label? If there are many D's to one B, then you can't just have one label that will be able to display
            all the values.


            The label is presented at the B level, but cardinality is not the issue here, because:

            There is a one-to-one between B's and C's.
            There is a many-to-one between C's and D's (that is, there is one D for many C's).

            So, given a B, I can get its corresponding C. And then, with that C object, I can get its parent D object.
            • 3. Re: Newbie Help Needed: Data Binding
              Level 7

              "Noreaster76" <webforumsuser@macromedia.com> wrote in message
              news:g7qa7e$b3i$1@forums.macromedia.com...
              > Okay, lemme see if I can possibly explain this issue clearly enough...
              > (The
              > whole explanation of the object graph may very well be superfluous, so you
              > can
              > probably skip to the bottom.)
              >
              > I have a whole object graph that I've downloaded from my server to my Flex
              > client. Here's the general gist of object relationships (and I have to
              > lay it
              > out this way because there's not really any way to sketch on a whiteboard
              > the
              > object graph):
              >

              > Object A is a parent of object B, and there is a one-to-many relationship
              > between the two. That is, there is one A to many B's.
              > There is a one-to-one relationship between Object B and Object C.
              > There is a many-to-one relationship between Object C and Object D. That
              > is,
              > there are many C's to one D.
              > There is a many-to-one relationship between Object D and Object E. That
              > is,
              > there are many D's to one E.
              > There is a many-to-one relationship between Object E and Object F. That
              > is,
              > there are many E's to one F.
              >

              > Now, because I am only given information from the user as far as which
              > object
              > A is the chosen object (that is, I'm not told right off the bat which B's,
              > C's,
              > D's, E's, and F's to pull from the server), I have a series of events
              > being
              > fired and listened to, so the sequence of steps pretty much goes like
              > this:
              >

              > User chooses a particular object A.
              > I pull A from the server.
              > I pull all of A's children (the B objects).
              > I look at the keys stored in the B's and pull the corresponding C's.
              > I look at the keys stored in the C's and pull their parents, the D's.
              > I look at the keys stored in the D's and pull their parents, the E's.
              > I look at the keys stored in the E's and pull their parents, the F's.
              >

              > Now, here's where I'm having an issue:
              > The B objects store a Date object called startTime. The D objects store an
              > integer called runTimeMillis (the runtime of the video, in milliseconds).
              > I
              > need to somehow present endTime, which is simply the sum of startTime +
              > runTimeMillis. But I have to do it in a data binding because the D
              > objects are
              > downloaded later than the B objects. But I've tried so many different
              > ways of
              > coding it, and nothing seems to work. Here's where I'm at:
              >
              > <mx:DateFormatter id="hmmssaFormatter" formatString="L:NN:SSA"/>
              > ...
              > <mx:Label text="{hmmssaFormatter.format(B.startTime +
              > B.C.D.runTimeMillis)}"
              > fontWeight="bold"/>
              >
              >
              > The only thing I get in my client is a blank label. What am I doing
              > wrong?
              > The following seems to work just fine in displaying the start time of the
              > video:
              >
              > <mx:Label text="{hmmssaFormatter.format(B.startTime)}" fontWeight="bold"/>
              >
              > But adding a number of milliseconds doesn't seem to work at all. Can
              > anyone
              > shed some light on the matter? Thanks!

              I still think there's something unexpected going on with your data. In the
              function where you set C and D, can you put a breakpoint and inspect the
              variables? You could also probably put a break point in the formatter and
              see shat has been passed in to it.

              HTH;

              Amy


              • 4. Re: Newbie Help Needed: Data Binding
                Noreaster76 Level 1
                Sorry, Charlie, wrong tuna. I have verified conclusively that the data has been loaded fine. I made a custom formatter that accepts numbers instead of Dates or Strings. This custom formatter extends DateFormatter and simply constructs a new Date from the number passed in, and forwards the format() call to super.format(). With this new custom formatter, I get what I wanted:

                <mx:Label text="{myHmmssaFormatter.format(B.startTime.valueOf() + B.C.D.runTimeMillis)}" fontWeight="bold"/>

                closely enough replicates the following:

                <mx:Label text="{hmmssaFormatter.format(B.startTime + B.C.D.runTimeMillis)}" fontWeight="bold"/>

                where the formatters are defined as follows:

                <mx:DateFormatter id="hmmssaFormatter" formatString="L:NN:SS A"/>
                <!-- why is this separate formatter necessary? argh! -->
                <util:MyDateFormatter id="myHmmssaFormatter" formatString="L:NN:SS A"/>

                So, as whined about in the comment immediately above, why did I have to go through the pain of creating my own fomatter that takes in a number? Surely there must be a way to add X+Y and submit the result to DateFormatter.format(), no?
                • 5. Newbie Help Needed: Data Binding
                  Gregory Lafrance Level 6
                  No doubt this is an extreme over-simplification, and may not in fact solve your problem:

                  DateFormatter.format(new Date(x + y))
                  • 6. Re: Newbie Help Needed: Data Binding
                    Noreaster76 Level 1
                    Unfortunately, I tried that, and it didn't work. All I got was a blank component. Can "new Date()" be done within a binding?
                    • 7. Re: Newbie Help Needed: Data Binding
                      Noreaster76 Level 1
                      Bump. What do I need to do in order to get something like

                      DateFormatter.format(new Date(x + y))

                      to work? Does that statement work for anyone else?