1 Reply Latest reply on Jul 11, 2007 1:59 PM by big4head

    The Phantom of the Operator

    big4head
      I am a relative Flex newbie with a Flash/DHTML background. I have created a List. Its itemRenderer is a custom component and the DataProvider is an ArrayCollection. The List supports Drag and Drop to reorder components and each component in the List has a "close" button to remove itself from the List. My question has to do with the (seemingly) unpredictable behavior of the itemRenderer in the above situations.

      1. Drag Drop: I have dragEnabled, dragMoveEnabled and dropEnabled all set to true in the List. Upon the completion of a drop however, it seems as if there is a "phantom" List item that is created. For example, say I have 3 components in the List labeled 1, 2 and 3. When I drag drop component 3 between 1 and 2 I will see them ordered 1-3-2. However if I then drag drop component 2 between 1 and 3 they are ordered 1-3-3 - a new component 3 is created and 2 is hidden. I say 2 is hidden for if I again drag drop the last component (labeled 3) between the first and second components (labeled 1 and 3) the components are now once again ordered 1-2-3, with the second component labeled 3 now hidden!

      2 Closing: I have learned about the capricious nature of itemRenderers so that the close button on the List components removes only that instance from the dataProvider and the itemRenderer properly updates the List, at least in what is physically displayed. However I am again presented with the existence of a phantom or hidden list item as when I add a new item to the list the old items are re-added to the List display. To illustrate using the above example. if I delete Item 2 in my 1-2-3 configuration above, it will be removed from the display, but adding a new component (supposedly blank) below it will re-add the component labeled 2 to the List. Furthermore, if I again add a new component my phantom duplicate component 3 will return!

      I had speculated that the itemRenderer on initialization had created a default item before the dataProvider was set. I therefore set the itemRenderer after the dataProvider, but that didn't help or change the above behavior. I then speculated that there was some laxness in my creation and destruction of dataProvider items, so I added a funtion to wipe out and then reset the itemRenderer. Still no dice. I add items by simply adding a new array to the ArrayCollection:

      currentDP = new Array([{fn: '', sp: '', ss: '', lo: '', lvl: level, initial: false}]);
      targetData.addItem(currentDP);

      I similarly remove items using the dataProvider (aswb is the component instance in the List):

      var ASWProxy:IListItemRenderer = aswb as IListItemRenderer;
      var idx:int = cmp.itemRendererToIndex(ASWProxy);
      targetData.removeItemAt(idx);

      I would like to be able to test more and "re-initilize" the List by wiping out the itemRenderers and re-acquiring them from the dataProvider, but the dataProvider stores variables that do not map directly to the itemRenderer's TextFields and ComboBoxes and I am unclear as to how the individual itemRenderers programatically reference its dataProvider item.

      I have spent a lot of time with this and made slow, incremental progress. Don't get me wrong - I'm sure it will seem like a great learning opportunity in retrospect. But can anyone point me in the right direction here?

      Thanks again for all your help,

      RG
        • 1. Re: The Phantom of the Operator
          big4head Level 1
          UPDATE: I have figured out how to "re-initilize" the List (using the data property of the itemRenderer), but this still does not address the problem of the phantom items that reappear on dragdrop and adding new items. Have I perhaps improperly set up Drag Drop and/or my close/delete button?

          I would also like to disallow dragdrop on the first list item (I have already hidden the close box); is there a way to do this without writing a custom DragDrop implementation from scratch?

          RG