13 Replies Latest reply on Jun 17, 2011 3:57 PM by pauland

    ArrayCollection is acting crazy. Is it just me?? What is happening here?

    Devtron Level 3

      Ok, I am either crazy or I am losing it. Probably both.

       

      Here is my situation:

      I am trying to initialize (and color the days of) a bunch of date values in several Calendar controls. This works if I use one date.

       

      In my code, I have a loop and I increment date values in the loop. I need to write those date values into an ArrayCollection, which is bound to, and used for, the dateCollection of my Calendar controls. This essentially will color the days selected I am setting into the ArrayCollection.

       

      Here is my code:

      dateCollection--screenshot.png

       

      This is where it gets strange. If I "trace" my date values, they are 100% correct. but if I create a Watch Expression, for _dateCollection, and I look at the values in the ArrayCollection there, the dates are wrong, and they are all the same!!

       

      Here is my trace output and you can see, the dateCollection is not getting the correct date values:

      _currentDate:Wed Sep 29 12:40:48 GMT-0500 2010
      written event, in date collection date:Wed Sep 29 12:40:48 GMT-0500 2010
      _currentDate:Thu Sep 30 12:40:48 GMT-0500 2010
      written event, in date collection date:Thu Sep 30 12:40:48 GMT-0500 2010
      _currentDate:Fri Oct 1 12:40:48 GMT-0500 2010
      written event, in date collection date:Fri Oct 1 12:40:48 GMT-0500 2010
      _currentDate:Sat Oct 2 12:40:48 GMT-0500 2010
      written event, in date collection date:Sat Oct 2 12:40:48 GMT-0500 2010
      _currentDate:Sun Oct 3 12:40:48 GMT-0500 2010
      written event, in date collection date:Sun Oct 3 12:40:48 GMT-0500 2010
      _currentDate:Mon Oct 4 12:40:48 GMT-0500 2010
      written event, in date collection date:Mon Oct 4 12:40:48 GMT-0500 2010
      _currentDate:Tue Oct 5 12:40:48 GMT-0500 2010
      written event, in date collection date:Tue Oct 5 12:40:48 GMT-0500 2010
      _currentDate:Wed Oct 6 12:40:48 GMT-0500 2010
      written event, in date collection date:Wed Oct 6 12:40:48 GMT-0500 2010
      _currentDate:Thu Oct 7 12:40:48 GMT-0500 2010
      written event, in date collection date:Thu Oct 7 12:40:48 GMT-0500 2010
      _currentDate:Fri Oct 8 12:40:48 GMT-0500 2010
      written event, in date collection date:Fri Oct 8 12:40:48 GMT-0500 2010
      _currentDate:Sat Oct 9 12:40:48 GMT-0500 2010
      written event, in date collection date:Sat Oct 9 12:40:48 GMT-0500 2010
      _currentDate:Sun Oct 10 12:40:48 GMT-0500 2010
      written event, in date collection date:Sun Oct 10 12:40:48 GMT-0500 2010
      _currentDate:Mon Oct 11 12:40:48 GMT-0500 2010
      written event, in date collection date:Mon Oct 11 12:40:48 GMT-0500 2010
      _currentDate:Tue Oct 12 12:40:48 GMT-0500 2010
      written event, in date collection date:Tue Oct 12 12:40:48 GMT-0500 2010
      _currentDate:Wed Oct 13 12:40:48 GMT-0500 2010
      written event, in date collection date:Wed Oct 13 12:40:48 GMT-0500 2010
      _currentDate:Thu Oct 14 12:40:48 GMT-0500 2010
      written event, in date collection date:Thu Oct 14 12:40:48 GMT-0500 2010
      _currentDate:Fri Oct 15 12:40:48 GMT-0500 2010
      written event, in date collection date:Fri Oct 15 12:40:48 GMT-0500 2010
      _currentDate:Sat Oct 16 12:40:48 GMT-0500 2010
      written event, in date collection date:Sat Oct 16 12:40:48 GMT-0500 2010
      _currentDate:Sun Oct 17 12:40:48 GMT-0500 2010
      written event, in date collection date:Sun Oct 17 12:40:48 GMT-0500 2010
      _currentDate:Mon Oct 18 12:40:48 GMT-0500 2010
      written event, in date collection date:Mon Oct 18 12:40:48 GMT-0500 2010
      _currentDate:Tue Oct 19 12:40:48 GMT-0500 2010
      written event, in date collection date:Tue Oct 19 12:40:48 GMT-0500 2010
      _currentDate:Wed Oct 20 12:40:48 GMT-0500 2010
      written event, in date collection date:Wed Oct 20 12:40:48 GMT-0500 2010
      _currentDate:Thu Oct 21 12:40:48 GMT-0500 2010
      written event, in date collection date:Thu Oct 21 12:40:48 GMT-0500 2010
      _currentDate:Fri Oct 22 12:40:48 GMT-0500 2010
      written event, in date collection date:Fri Oct 22 12:40:48 GMT-0500 2010
      _currentDate:Sat Oct 23 12:40:48 GMT-0500 2010
      written event, in date collection date:Sat Oct 23 12:40:48 GMT-0500 2010
      _currentDate:Sun Oct 24 12:40:48 GMT-0500 2010
      written event, in date collection date:Sun Oct 24 12:40:48 GMT-0500 2010
      _currentDate:Mon Oct 25 12:40:48 GMT-0500 2010
      written event, in date collection date:Mon Oct 25 12:40:48 GMT-0500 2010
      _currentDate:Tue Oct 26 12:40:48 GMT-0500 2010
      written event, in date collection date:Tue Oct 26 12:40:48 GMT-0500 2010
      _currentDate:Wed Oct 27 12:40:48 GMT-0500 2010
      written event, in date collection date:Wed Oct 27 12:40:48 GMT-0500 2010
      _currentDate:Thu Oct 28 12:40:48 GMT-0500 2010
      written event, in date collection date:Thu Oct 28 12:40:48 GMT-0500 2010
      _currentDate:Mon Mar 28 12:40:48 GMT-0500 2011
      written event, in date collection date:Mon Mar 28 12:40:48 GMT-0500 2011

      date in datecollection: ----> Tue Mar 29 12:40:48 GMT-0500 2011
      date in datecollection: ----> Tue Mar 29 12:40:48 GMT-0500 2011
      date in datecollection: ----> Tue Mar 29 12:40:48 GMT-0500 2011
      date in datecollection: ----> Tue Mar 29 12:40:48 GMT-0500 2011
      date in datecollection: ----> Tue Mar 29 12:40:48 GMT-0500 2011
      date in datecollection: ----> Tue Mar 29 12:40:48 GMT-0500 2011
      date in datecollection: ----> Tue Mar 29 12:40:48 GMT-0500 2011
      date in datecollection: ----> Tue Mar 29 12:40:48 GMT-0500 2011
      date in datecollection: ----> Tue Mar 29 12:40:48 GMT-0500 2011
      date in datecollection: ----> Tue Mar 29 12:40:48 GMT-0500 2011
      date in datecollection: ----> Tue Mar 29 12:40:48 GMT-0500 2011
      date in datecollection: ----> Tue Mar 29 12:40:48 GMT-0500 2011
      date in datecollection: ----> Tue Mar 29 12:40:48 GMT-0500 2011
      date in datecollection: ----> Tue Mar 29 12:40:48 GMT-0500 2011
      date in datecollection: ----> Tue Mar 29 12:40:48 GMT-0500 2011
      date in datecollection: ----> Tue Mar 29 12:40:48 GMT-0500 2011
      date in datecollection: ----> Tue Mar 29 12:40:48 GMT-0500 2011
      date in datecollection: ----> Tue Mar 29 12:40:48 GMT-0500 2011
      date in datecollection: ----> Tue Mar 29 12:40:48 GMT-0500 2011
      date in datecollection: ----> Tue Mar 29 12:40:48 GMT-0500 2011
      date in datecollection: ----> Tue Mar 29 12:40:48 GMT-0500 2011
      date in datecollection: ----> Tue Mar 29 12:40:48 GMT-0500 2011
      date in datecollection: ----> Tue Mar 29 12:40:48 GMT-0500 2011
      date in datecollection: ----> Tue Mar 29 12:40:48 GMT-0500 2011
      date in datecollection: ----> Tue Mar 29 12:40:48 GMT-0500 2011
      date in datecollection: ----> Tue Mar 29 12:40:48 GMT-0500 2011
      date in datecollection: ----> Tue Mar 29 12:40:48 GMT-0500 2011
      date in datecollection: ----> Tue Mar 29 12:40:48 GMT-0500 2011
      date in datecollection: ----> Tue Mar 29 12:40:48 GMT-0500 2011
      date in datecollection: ----> Tue Mar 29 12:40:48 GMT-0500 2011
      date in datecollection: ----> Tue Mar 29 12:40:48 GMT-0500 2011

       

       

      My main question is, why are ALL the dates in my ArrayCollection the same? Have I missed something? Have I been staring at this for too long? Is this a bug in ArrayCollection? Help!

        • 1. Re: ArrayCollection is acting crazy. Is it just me?? What is happening here?
          Devtron Level 3

          dateCollection--screenshot2.png

           

          ^ As you can see here, in the Watch window (in red), the values get updated each time I perform an [addItem] on the _dateCollection.

           

          Why do all of the values, in each Array Element, get updated? This is really weird to me...am I missing something?

          • 2. Re: ArrayCollection is acting crazy. Is it just me?? What is happening here?
            saisri2k2 Level 4

            You have to create a new object ie.,some date object on every for loop. you are using the same object for all the loops.. so, eventually all of them get updated when you try to update .

             

            so you code should look like this

             

            for (XYUZ){

             

            createNewDateEvent = new CreateNewDateEvent(xxx);

             

            .

            .

            .

            .

            .

            array.addItem(createNewDateEvent );

             

            }

            • 3. Re: ArrayCollection is acting crazy. Is it just me?? What is happening here?
              Devtron Level 3

              That's what I thought too. I tried that, and it didnt work. Anyways, it is better to "new" the objects in the loop, you are correct. I went ahead and did that, but still get the same bug/problem.

               

              Here is the updated code:

              dateCollection--screenshot.png

               

              And here is the updated trace/output:

               

              _currentDate:Wed Sep 29 13:31:20 GMT-0500 2010
              written event, in date collection date:Wed Sep 29 13:31:20 GMT-0500 2010
              _currentDate:Thu Sep 30 13:31:20 GMT-0500 2010
              written event, in date collection date:Thu Sep 30 13:31:20 GMT-0500 2010
              _currentDate:Fri Oct 1 13:31:20 GMT-0500 2010
              written event, in date collection date:Fri Oct 1 13:31:20 GMT-0500 2010
              _currentDate:Sat Oct 2 13:31:20 GMT-0500 2010
              written event, in date collection date:Sat Oct 2 13:31:20 GMT-0500 2010
              _currentDate:Sun Oct 3 13:31:20 GMT-0500 2010
              written event, in date collection date:Sun Oct 3 13:31:20 GMT-0500 2010
              _currentDate:Mon Oct 4 13:31:20 GMT-0500 2010
              written event, in date collection date:Mon Oct 4 13:31:20 GMT-0500 2010
              _currentDate:Tue Oct 5 13:31:20 GMT-0500 2010
              written event, in date collection date:Tue Oct 5 13:31:20 GMT-0500 2010
              _currentDate:Wed Oct 6 13:31:20 GMT-0500 2010
              written event, in date collection date:Wed Oct 6 13:31:20 GMT-0500 2010
              _currentDate:Thu Oct 7 13:31:20 GMT-0500 2010
              written event, in date collection date:Thu Oct 7 13:31:20 GMT-0500 2010
              _currentDate:Fri Oct 8 13:31:20 GMT-0500 2010
              written event, in date collection date:Fri Oct 8 13:31:20 GMT-0500 2010
              _currentDate:Sat Oct 9 13:31:20 GMT-0500 2010
              written event, in date collection date:Sat Oct 9 13:31:20 GMT-0500 2010
              _currentDate:Sun Oct 10 13:31:20 GMT-0500 2010
              written event, in date collection date:Sun Oct 10 13:31:20 GMT-0500 2010
              _currentDate:Mon Oct 11 13:31:20 GMT-0500 2010
              written event, in date collection date:Mon Oct 11 13:31:20 GMT-0500 2010
              _currentDate:Tue Oct 12 13:31:20 GMT-0500 2010
              written event, in date collection date:Tue Oct 12 13:31:20 GMT-0500 2010
              _currentDate:Wed Oct 13 13:31:20 GMT-0500 2010
              written event, in date collection date:Wed Oct 13 13:31:20 GMT-0500 2010
              _currentDate:Thu Oct 14 13:31:20 GMT-0500 2010
              written event, in date collection date:Thu Oct 14 13:31:20 GMT-0500 2010
              _currentDate:Fri Oct 15 13:31:20 GMT-0500 2010
              written event, in date collection date:Fri Oct 15 13:31:20 GMT-0500 2010
              _currentDate:Sat Oct 16 13:31:20 GMT-0500 2010
              written event, in date collection date:Sat Oct 16 13:31:20 GMT-0500 2010
              _currentDate:Sun Oct 17 13:31:20 GMT-0500 2010
              written event, in date collection date:Sun Oct 17 13:31:20 GMT-0500 2010
              _currentDate:Mon Oct 18 13:31:20 GMT-0500 2010
              written event, in date collection date:Mon Oct 18 13:31:20 GMT-0500 2010
              _currentDate:Tue Oct 19 13:31:20 GMT-0500 2010
              written event, in date collection date:Tue Oct 19 13:31:20 GMT-0500 2010
              _currentDate:Wed Oct 20 13:31:20 GMT-0500 2010
              written event, in date collection date:Wed Oct 20 13:31:20 GMT-0500 2010
              _currentDate:Thu Oct 21 13:31:20 GMT-0500 2010
              written event, in date collection date:Thu Oct 21 13:31:20 GMT-0500 2010
              _currentDate:Fri Oct 22 13:31:20 GMT-0500 2010
              written event, in date collection date:Fri Oct 22 13:31:20 GMT-0500 2010
              _currentDate:Sat Oct 23 13:31:20 GMT-0500 2010
              written event, in date collection date:Sat Oct 23 13:31:20 GMT-0500 2010
              _currentDate:Sun Oct 24 13:31:20 GMT-0500 2010
              written event, in date collection date:Sun Oct 24 13:31:20 GMT-0500 2010
              _currentDate:Mon Oct 25 13:31:20 GMT-0500 2010
              written event, in date collection date:Mon Oct 25 13:31:20 GMT-0500 2010
              _currentDate:Tue Oct 26 13:31:20 GMT-0500 2010
              written event, in date collection date:Tue Oct 26 13:31:20 GMT-0500 2010
              _currentDate:Wed Oct 27 13:31:20 GMT-0500 2010
              written event, in date collection date:Wed Oct 27 13:31:20 GMT-0500 2010
              _currentDate:Thu Oct 28 13:31:20 GMT-0500 2010
              written event, in date collection date:Thu Oct 28 13:31:20 GMT-0500 2010
              _currentDate:Mon Mar 28 13:31:20 GMT-0500 2011
              written event, in date collection date:Mon Mar 28 13:31:20 GMT-0500 2011
              date in datecollection: ----> Tue Mar 29 13:31:20 GMT-0500 2011
              date in datecollection: ----> Tue Mar 29 13:31:20 GMT-0500 2011
              date in datecollection: ----> Tue Mar 29 13:31:20 GMT-0500 2011
              date in datecollection: ----> Tue Mar 29 13:31:20 GMT-0500 2011
              date in datecollection: ----> Tue Mar 29 13:31:20 GMT-0500 2011
              date in datecollection: ----> Tue Mar 29 13:31:20 GMT-0500 2011
              date in datecollection: ----> Tue Mar 29 13:31:20 GMT-0500 2011
              date in datecollection: ----> Tue Mar 29 13:31:20 GMT-0500 2011
              date in datecollection: ----> Tue Mar 29 13:31:20 GMT-0500 2011
              date in datecollection: ----> Tue Mar 29 13:31:20 GMT-0500 2011
              date in datecollection: ----> Tue Mar 29 13:31:20 GMT-0500 2011
              date in datecollection: ----> Tue Mar 29 13:31:20 GMT-0500 2011
              date in datecollection: ----> Tue Mar 29 13:31:20 GMT-0500 2011
              date in datecollection: ----> Tue Mar 29 13:31:20 GMT-0500 2011
              date in datecollection: ----> Tue Mar 29 13:31:20 GMT-0500 2011
              date in datecollection: ----> Tue Mar 29 13:31:20 GMT-0500 2011
              date in datecollection: ----> Tue Mar 29 13:31:20 GMT-0500 2011
              date in datecollection: ----> Tue Mar 29 13:31:20 GMT-0500 2011
              date in datecollection: ----> Tue Mar 29 13:31:20 GMT-0500 2011
              date in datecollection: ----> Tue Mar 29 13:31:20 GMT-0500 2011
              date in datecollection: ----> Tue Mar 29 13:31:20 GMT-0500 2011
              date in datecollection: ----> Tue Mar 29 13:31:20 GMT-0500 2011
              date in datecollection: ----> Tue Mar 29 13:31:20 GMT-0500 2011
              date in datecollection: ----> Tue Mar 29 13:31:20 GMT-0500 2011
              date in datecollection: ----> Tue Mar 29 13:31:20 GMT-0500 2011
              date in datecollection: ----> Tue Mar 29 13:31:20 GMT-0500 2011
              date in datecollection: ----> Tue Mar 29 13:31:20 GMT-0500 2011
              date in datecollection: ----> Tue Mar 29 13:31:20 GMT-0500 2011
              date in datecollection: ----> Tue Mar 29 13:31:20 GMT-0500 2011
              date in datecollection: ----> Tue Mar 29 13:31:20 GMT-0500 2011
              date in datecollection: ----> Tue Mar 29 13:31:20 GMT-0500 2011

               

               

               

              same problem, any other ideas? Nice suggestion...I had actually tried that before tho

              • 4. Re: ArrayCollection is acting crazy. Is it just me?? What is happening here?
                BhaskerChari Level 4

                Hi Devtron,

                 

                Since you are adding the same object createNewDateEntryEvent for all the items you are adding to ArrayCollection. as and when your counter gets incremented all the previous items in the ArrayCollection also gets updated even if you create new instance for CreateNewDateEntryEvent.

                 

                If you notice in your ArrayCollection you will notice that Tue Mar 29 13:31:20 GMT-0500 2011 is the date present in all the items in ArrayCollection which is the date added to ArrayCollection in last ArrayCollection which depicts that all your items previosly added are also getting effected whenever you add new item to ArrayCollection.

                 

                In order to have the diifferent items added to the ArrayCollection you need to declare new variable for each and every loop you iterate as shown below.

                 

                 

                //This is the solution

                for(var i:int=0; i < _dateDiffCount; i++)
                   {
                    if(_dayMap.charAt(1) != ".")
                    {
                     var createNewDateEntryEvent:CreateNewDateEntryEvent= new CreateNewDateEntryEventCreateNewDateEntryEvent.CREATE_NEW_DATE_ENTRY);
                     createNewDateEntryEvent.color = 16711680;
                     //Have the remaining lines of code as same...
                    }
                     
                   }

                 

                So if you look at the above code I have declared the variable createNewDateEntryEvent with in the for loop only ...where as in your code you declared it outside the for loop and you are assigning the parameters next time of iteration to the same object so since the same item is already added in the previous iteration and since now you are changing the properties in the current iteration the values of the previous item added will also be changed.

                 

                 

                //This also not gonna work for you as you decalred here the variable outside the for loop and trying to reuse the same varible for each and every iteration where as in the above case I declared the variable within the for loop.

                var createNewDateEntryEvent:CreateNewDateEntryEvent= new CreateNewDateEntryEventCreateNewDateEntryEvent.CREATE_NEW_DATE_ENTRY);

                for(var i:int=0; i < _dateDiffCount; i++)
                   {
                    if(_dayMap.charAt(1) != ".")
                    {
                     createNewDateEntryEvent:CreateNewDateEntryEvent= new CreateNewDateEntryEventCreateNewDateEntryEvent.CREATE_NEW_DATE_ENTRY);
                     createNewDateEntryEvent.color = 16711680;
                     //Have the remaining lines of code as same...
                    }
                     
                   }

                 

                So even if you instantiate new instance for createNewDateEntryEvent also it is not going to work for you ...So you need to declare new variable in for loop for each and every iteration...then only you can avoid this problem.

                 

                 

                Hope you noticed the difference and I am sure this might resolve your problem.

                 

                 

                Thanks,

                Bhasker

                • 5. Re: ArrayCollection is acting crazy. Is it just me?? What is happening here?
                  Devtron Level 3

                  ^ No, look at my response above yours. I moved the "new"/construction code into the for loop and I received the same problem/bug, as shown in my screenshots and update trace/output below it.

                   

                   

                   

                  I talked to a co-worker and he suggested I instantiate the "_currentDate" variable inside the for loop as well. This fixed the problem.

                  Apparently, the ArrayCollection keeps that object in memory, or is bound to it. I am unsure what its doing or why it would even do that. Nothing is wrong with my code, as it should work as intended.

                   

                  Here is the fix (sorry I removed the trace statements after I got it working, sue me):

                  dateCollection--screenshot--fix.png

                   

                   

                  Here is the correct trace/output:

                   

                  _currentDate:Wed Sep 1 15:15:31 GMT-0500 2010
                  written event, in date collection date:Wed Sep 1 15:15:31 GMT-0500 2010
                  _currentDate:Thu Sep 2 15:15:31 GMT-0500 2010
                  written event, in date collection date:Thu Sep 2 15:15:31 GMT-0500 2010
                  _currentDate:Fri Sep 3 15:15:31 GMT-0500 2010
                  written event, in date collection date:Fri Sep 3 15:15:31 GMT-0500 2010
                  _currentDate:Sat Sep 4 15:15:31 GMT-0500 2010
                  written event, in date collection date:Sat Sep 4 15:15:31 GMT-0500 2010
                  _currentDate:Sun Sep 5 15:15:31 GMT-0500 2010
                  written event, in date collection date:Sun Sep 5 15:15:31 GMT-0500 2010
                  _currentDate:Mon Sep 6 15:15:31 GMT-0500 2010
                  written event, in date collection date:Mon Sep 6 15:15:31 GMT-0500 2010
                  _currentDate:Tue Sep 7 15:15:31 GMT-0500 2010
                  written event, in date collection date:Tue Sep 7 15:15:31 GMT-0500 2010
                  _currentDate:Wed Sep 8 15:15:31 GMT-0500 2010
                  written event, in date collection date:Wed Sep 8 15:15:31 GMT-0500 2010
                  _currentDate:Thu Sep 9 15:15:31 GMT-0500 2010
                  written event, in date collection date:Thu Sep 9 15:15:31 GMT-0500 2010
                  _currentDate:Fri Sep 10 15:15:31 GMT-0500 2010
                  written event, in date collection date:Fri Sep 10 15:15:31 GMT-0500 2010
                  _currentDate:Sat Sep 11 15:15:31 GMT-0500 2010
                  written event, in date collection date:Sat Sep 11 15:15:31 GMT-0500 2010
                  _currentDate:Sun Sep 12 15:15:31 GMT-0500 2010
                  written event, in date collection date:Sun Sep 12 15:15:31 GMT-0500 2010
                  _currentDate:Mon Sep 13 15:15:31 GMT-0500 2010
                  written event, in date collection date:Mon Sep 13 15:15:31 GMT-0500 2010
                  _currentDate:Tue Sep 14 15:15:31 GMT-0500 2010
                  written event, in date collection date:Tue Sep 14 15:15:31 GMT-0500 2010
                  _currentDate:Wed Sep 15 15:15:31 GMT-0500 2010
                  written event, in date collection date:Wed Sep 15 15:15:31 GMT-0500 2010
                  _currentDate:Thu Sep 16 15:15:31 GMT-0500 2010
                  written event, in date collection date:Thu Sep 16 15:15:31 GMT-0500 2010
                  _currentDate:Fri Sep 17 15:15:31 GMT-0500 2010
                  written event, in date collection date:Fri Sep 17 15:15:31 GMT-0500 2010
                  _currentDate:Sat Sep 18 15:15:31 GMT-0500 2010
                  written event, in date collection date:Sat Sep 18 15:15:31 GMT-0500 2010
                  _currentDate:Sun Sep 19 15:15:31 GMT-0500 2010
                  written event, in date collection date:Sun Sep 19 15:15:31 GMT-0500 2010
                  _currentDate:Mon Sep 20 15:15:31 GMT-0500 2010
                  written event, in date collection date:Mon Sep 20 15:15:31 GMT-0500 2010
                  _currentDate:Tue Sep 21 15:15:31 GMT-0500 2010
                  written event, in date collection date:Tue Sep 21 15:15:31 GMT-0500 2010
                  _currentDate:Wed Sep 22 15:15:31 GMT-0500 2010
                  written event, in date collection date:Wed Sep 22 15:15:31 GMT-0500 2010
                  _currentDate:Thu Sep 23 15:15:31 GMT-0500 2010
                  written event, in date collection date:Thu Sep 23 15:15:31 GMT-0500 2010
                  _currentDate:Fri Sep 24 15:15:31 GMT-0500 2010
                  written event, in date collection date:Fri Sep 24 15:15:31 GMT-0500 2010
                  _currentDate:Sat Sep 25 15:15:31 GMT-0500 2010
                  written event, in date collection date:Sat Sep 25 15:15:31 GMT-0500 2010
                  _currentDate:Sun Sep 26 15:15:31 GMT-0500 2010
                  written event, in date collection date:Sun Sep 26 15:15:31 GMT-0500 2010
                  _currentDate:Mon Sep 27 15:15:31 GMT-0500 2010
                  written event, in date collection date:Mon Sep 27 15:15:31 GMT-0500 2010
                  _currentDate:Tue Sep 28 15:15:31 GMT-0500 2010
                  written event, in date collection date:Tue Sep 28 15:15:31 GMT-0500 2010
                  _currentDate:Wed Sep 29 15:15:31 GMT-0500 2010
                  written event, in date collection date:Wed Sep 29 15:15:31 GMT-0500 2010
                  _currentDate:Thu Sep 30 15:15:31 GMT-0500 2010
                  written event, in date collection date:Thu Sep 30 15:15:31 GMT-0500 2010
                  _currentDate:Mon Feb 28 15:15:31 GMT-0600 2011
                  written event, in date collection date:Mon Feb 28 15:15:31 GMT-0600 2011
                  date in datecollection: ----> Wed Sep 1 15:15:31 GMT-0500 2010
                  date in datecollection: ----> Thu Sep 2 15:15:31 GMT-0500 2010
                  date in datecollection: ----> Fri Sep 3 15:15:31 GMT-0500 2010
                  date in datecollection: ----> Sat Sep 4 15:15:31 GMT-0500 2010
                  date in datecollection: ----> Sun Sep 5 15:15:31 GMT-0500 2010
                  date in datecollection: ----> Mon Sep 6 15:15:31 GMT-0500 2010
                  date in datecollection: ----> Tue Sep 7 15:15:31 GMT-0500 2010
                  date in datecollection: ----> Wed Sep 8 15:15:31 GMT-0500 2010
                  date in datecollection: ----> Thu Sep 9 15:15:31 GMT-0500 2010
                  date in datecollection: ----> Fri Sep 10 15:15:31 GMT-0500 2010
                  date in datecollection: ----> Sat Sep 11 15:15:31 GMT-0500 2010
                  date in datecollection: ----> Sun Sep 12 15:15:31 GMT-0500 2010
                  date in datecollection: ----> Mon Sep 13 15:15:31 GMT-0500 2010
                  date in datecollection: ----> Tue Sep 14 15:15:31 GMT-0500 2010
                  date in datecollection: ----> Wed Sep 15 15:15:31 GMT-0500 2010
                  date in datecollection: ----> Thu Sep 16 15:15:31 GMT-0500 2010
                  date in datecollection: ----> Fri Sep 17 15:15:31 GMT-0500 2010
                  date in datecollection: ----> Sat Sep 18 15:15:31 GMT-0500 2010
                  date in datecollection: ----> Sun Sep 19 15:15:31 GMT-0500 2010
                  date in datecollection: ----> Mon Sep 20 15:15:31 GMT-0500 2010
                  date in datecollection: ----> Tue Sep 21 15:15:31 GMT-0500 2010
                  date in datecollection: ----> Wed Sep 22 15:15:31 GMT-0500 2010
                  date in datecollection: ----> Thu Sep 23 15:15:31 GMT-0500 2010
                  date in datecollection: ----> Fri Sep 24 15:15:31 GMT-0500 2010
                  date in datecollection: ----> Sat Sep 25 15:15:31 GMT-0500 2010
                  date in datecollection: ----> Sun Sep 26 15:15:31 GMT-0500 2010
                  date in datecollection: ----> Mon Sep 27 15:15:31 GMT-0500 2010
                  date in datecollection: ----> Tue Sep 28 15:15:31 GMT-0500 2010
                  date in datecollection: ----> Wed Sep 29 15:15:31 GMT-0500 2010
                  date in datecollection: ----> Thu Sep 30 15:15:31 GMT-0500 2010
                  date in datecollection: ----> Mon Feb 28 15:15:31 GMT-0600 2011

                   

                   

                   

                   

                   

                  The original code *should* work. Can someone explain why it would not?


                  This was a huge waste of half a day......and it makes us angry at FLEX

                   

                  Message was edited by: Devtron

                  • 6. Re: ArrayCollection is acting crazy. Is it just me?? What is happening here?
                    jmerrill2001

                    Wow, this bug was causing me insane amounts of pain as well for a similar situation I was in with ArrayCollection for a LineChart in Flex, and I also wasted half a day on this until I came across this post. 

                     

                    I was doing this:

                     

                    [Bindable]
                    private var _lineChartData:ArrayCollection;
                    
                    
                    
                    
                    
                    public function set keyingReportVO(value:KeyingReportVO):void
                    {
                              _recentKeyingReportVO = value;
                    
                    
                         _lineChartData.addItem(_recentKeyingReportVO);
                    }
                    
                    

                     

                    But the ArrayCollection was always showing the same values when I traced them - like they knew they were going to be replaced with a new value and therefore changed to be all the same new value! ugh!

                     

                    But when I changed it to this hack, it worked:

                     

                    [Bindable]
                    private var _lineChartData:ArrayCollection;
                    
                    
                    
                    
                    
                    public function set keyingReportVO(value:KeyingReportVO):void
                    {
                         _recentKeyingReportVO = value;
                    
                         var newKeyingReportVO:KeyingReportVO = new KeyingReportVO;
                         newKeyingReportVO.kph = _recentKeyingReportVO.kph;
                         newKeyingReportVO.kphBaseline = _recentKeyingReportVO.kphBaseline;
                    
                    
                         _lineChartData.addItem(newKeyingReportVO);
                    }
                    
                    

                     

                    Thanks for posting the solution, this could have kept me digging for days! 

                     

                    Jason Merrill

                    Bank of America

                    • 7. Re: ArrayCollection is acting crazy. Is it just me?? What is happening here?
                      Devtron Level 3

                      No problem. This FLEX stuff really frustrates me sometimes, glad to know Im not the only one.

                      • 8. Re: ArrayCollection is acting crazy. Is it just me?? What is happening here?
                        pauland Level 4

                        Jason, that hack only works by hiding a bug elsewhere in your code. There is no bug otherwise.

                         

                        Somewhere, in the code before the assignment to keyingReportVO, you have a missing  "new".

                        • 9. Re: ArrayCollection is acting crazy. Is it just me?? What is happening here?
                          Flex harUI Adobe Employee

                          Post a small test case that reproduces the problem.

                          • 10. Re: ArrayCollection is acting crazy. Is it just me?? What is happening here?
                            pauland Level 4

                            Devtron, your original and "fixed" code contains a bug. In both cases you set the date attribute of the event to be the same date object every time, but you should be setting it to be a new date which is a copy of the current date. It's a bug in your code, not the compiler and an earlier respondent has already tried to explain this.

                            • 11. Re: ArrayCollection is acting crazy. Is it just me?? What is happening here?
                              Devtron Level 3

                              ^ Correct, you have to "new" the date object during each iteration.

                               

                              So much for re-usability...

                              • 12. Re: ArrayCollection is acting crazy. Is it just me?? What is happening here?
                                pauland Level 4

                                Devtron wrote:

                                 

                                ^ Correct, you have to "new" the date object during each iteration.

                                 

                                So much for re-usability...

                                 

                                The re-usability comment doesn't make sense. The ArrayCollection has references to date objects. If you want it to reference differrent objects, you must add differrent objects to it. Just changing the value in one object and repeatedly adding a reference to the same objects, just doesn't give the result you want - it's nothing to do with object re-use.

                                • 13. Re: ArrayCollection is acting crazy. Is it just me?? What is happening here?
                                  pauland Level 4

                                  Referring to the original post:

                                   

                                  original: createNewDateEntryEvent.date = _currentDate;


                                  should have been: createNewDateEntryEvent.date = new Date().setTime(_currentDate.valueOf());