4 Replies Latest reply on Feb 23, 2009 11:46 PM by ntsiii

    Wrong event handler being invoked when XMLList changed?

    WayneAtCrd
      I have a problem that happens reproducibly, but when I attach the debugger, it goes away.

      I have two AdvancedDataGrids, each having the data provider set up like this:

      private var xmlList: XMLListCollection = new XMLListCollection();;
      xmlList.addEventListener(CollectionEvent.COLLECTION_CHANGE, myEventHandler);
      var hierarchical:HierarchicalData = new HierarchicalData(xmlList);
      myGrid.dataProvider = hierarchical;

      I use a different "myEventHandler" for each of the two grids.
      The problem is that, for one of the grids, when the data changes, it invokes the other grid's event handler.

      Normally, I would think that there is some subtle coding error on my part. But when I attach a debugger, it works correctly!

      Does anybody have any theories about what could be wrong that would cause a problem like this, but work correctly when the debugger is attached?

      I was experiencing this problem with Flex 3.1, so I upgraded to 3.2 and still have the problem.


        • 1. Re: Wrong event handler being invoked when XMLList changed?
          Level 7

          "WayneAtCrd" <webforumsuser@macromedia.com> wrote in message
          news:gnn0or$39k$1@forums.macromedia.com...
          >I have a problem that happens reproducibly, but when I attach the debugger,
          >it
          > goes away.
          >
          > I have two AdvancedDataGrids, each having the data provider set up like
          > this:
          >
          > private var xmlList: XMLListCollection = new XMLListCollection();;
          > xmlList.addEventListener(CollectionEvent.COLLECTION_CHANGE,
          > myEventHandler);
          > var hierarchical:HierarchicalData = new HierarchicalData(xmlList);
          > myGrid.dataProvider = hierarchical;
          >
          > I use a different "myEventHandler" for each of the two grids.
          > The problem is that, for one of the grids, when the data changes, it
          > invokes
          > the other grid's event handler.
          >
          > Normally, I would think that there is some subtle coding error on my part.
          > But when I attach a debugger, it works correctly!
          >
          > Does anybody have any theories about what could be wrong that would cause
          > a
          > problem like this, but work correctly when the debugger is attached?
          >
          > I was experiencing this problem with Flex 3.1, so I upgraded to 3.2 and
          > still
          > have the problem.

          var hierarchical:HierarchicalData = new HierarchicalData(xmlList);

          This means that hierarchical is just wrappping xmlList. When one changes,
          the other changes, since they're the same thing. It's like saying:

          var you:Person = new Person(wayne);
          var car:carWithDriver = new carWithDriver(you);

          If you move the arm on you, the arm will move on the driver in the car, too,
          since it's you.


          • 2. Re: Wrong event handler being invoked when XMLList changed?
            WayneAtCrd Level 1
            Thanks Amy, but I'm using a "new XMLListcollection()" for each grid, not re-using the same one.
            • 3. Re: Wrong event handler being invoked when XMLList changed?
              WayneAtCrd Level 1
              Anybody have experience with problems that go away when using the debugger?
              • 4. Re: Wrong event handler being invoked when XMLList changed?
                ntsiii Level 3
                I'm with Amy. "new" just creates an instance, it does not assure independence. You have not shown enough code to convince me this is not the issue. Really, you have just shown 'sample' code. Or do bothe grids really call the same "myEventHandler"?