4 Replies Latest reply on Dec 13, 2010 8:41 AM by lavum

    Changing List's item renderer and layout causes exception

    tehxike1 Level 1

      I have buttons in my UI to switch a list between a tile view (thumbnails) and a list view (details).

       

      This code works:

           var layout:TileLayout = new TileLayout();

           resultsList.layout = layout;

       

           resultsList.itemRenderer = new ClassFactory(MediaTileRenderer);

       

      This code doesn't:

           var layout:VerticalLayout = new VerticalLayout();

           resultsList.layout = layout;

       

           resultsList.itemRenderer = new ClassFactory(MediaItemRenderer);

       

      It's not the item renderer's fault, I can use the tile renderer again in the second block of code and it will still explode.  If I swap the VerticalLayout for a TileLayout, it works fine.  HorizontalLayout explodes.

       

      The exception is occurring in LinearLayoutVector/remove (541):

      Error: invalidIndex

      at spark.layouts.supportClasses::LinearLayoutVector/remove()[E:\dev\4.x\frameworks\projects\ spark\src\spark\layouts\supportClasses\LinearLayoutVector.as:541]

      at spark.layouts::VerticalLayout/elementRemoved()[E:\dev\4.x\frameworks\projects\spark\src\s park\layouts\VerticalLayout.as:1311]

      at spark.components::DataGroup/http://www.adobe.com/2006/flex/mx/internal::itemRemoved()[E:\dev\4.x\frameworks\projects\s park\src\spark\components\DataGroup.as:1580]

      at spark.components::DataGroup/removeRendererAt()[E:\dev\4.x\frameworks\projects\spark\src\s park\components\DataGroup.as:625]

      at spark.components::DataGroup/removeAllItemRenderers()[E:\dev\4.x\frameworks\projects\spark \src\spark\components\DataGroup.as:642]

      at spark.components::DataGroup/set itemRenderer()[E:\dev\4.x\frameworks\projects\spark\src\spark\components\DataGroup.as:446 ]

      at spark.components::SkinnableDataContainer/set itemRenderer()[E:\dev\4.x\frameworks\projects\spark\src\spark\components\SkinnableDataCon tainer.as:420]

       

      Does anyone know why this doesn't work?  It seems like a fairly common idea- using a single list and toggling between different view modes.