2 Replies Latest reply on Sep 23, 2009 2:01 PM by Shongrunden

    outerDocument and spark item renderers

    Handycam Level 1

      I am trying to work with components using the principles discussed here and here, the Flex Cookbook beta and Peter deHaahn's site.

       

      This sort of thing, based on the Flex cookbook link above, seems to work:

       

      <s:List id="startersList" dataProvider="{starters}" width="100%" skinClass="skins.MenuSectionListSkin">
           <s:itemRenderer>
                <fx:Component>
                    <s:ItemRenderer>
                        <s:HGroup>
                          <s:Label text="{XML(data).title}" />
                          <s:Button id="remove" label="X"  click="outerDocument.deleteItem(event)"/>
                        </s:HGroup>
                     </s:ItemRenderer>
                </fx:Component>
           </s:itemRenderer>
      </s:List>
      

       

      Except that the row does not get focus until the second click on the button...

       

      My main question, and why I am posting, is when I want to put this itemRenderer into a separate mxml component, the outserDocument no longer works.  I assume I will need to dispatch a custom event and then listen for it in the component?

       

      If so, how do I get the correct row that I should delete?  The function is:

       

      public function deleteItem(event:MouseEvent):void{        
           starters.removeItemAt(startersList.selectedIndex);
           starters.refresh();
      }
      

      I have multiple instances of this list, I would need to know:

      1. what row was clicked on

      2. which list this is (e.g. "starters", "sideDishes")

      3. which dataprovider to remove the member from the index in #1

       

      Assuming my button in the external item renderer has a click handler like:

       

      private function handleClickedDeleteButton(event:MouseEvent):void {
          this.dispatchEvent(new Event("deleteMenuItem"), true);
      }
      

       

       

      Is that correct?  But how do I get the 3 items mentioned above??