1 Reply Latest reply on Jun 21, 2013 9:19 AM by Bramblethorne

    Spark List ItemRenderer 'data' is null.

    Bramblethorne Level 1

      I'm using the exact same code in one location that I use in another, and yet upon the creationComplete event being dispatched within the itemRenderer, the first line of code, trace("data") returns "null".

       

      This code has been working fine for months and suddenly stopped working with no explanation.  I've lost two days under deadline fixing what shouldn't be broken and I'm no closer to a solution.  Very frustrated. Any help -greatly- appreciated.

       

      // Puddleglum.

       

      === Component relevant code containing spark list === Console output shown as comments

      [Bindable]

      public var itemArray:ArrayCollection = new ArrayCollection();

       

      [Bindable]

      private var gap:uint = 6;

       

      private var file:File;

      private var fileStream:FileStream;

      private var toolXML:XML;

       

      protected function creationCompleteHandler():void

      {

          trace("MyLibraryToolsPanel FUNCTION creationCompleteHandler()");

          file = parentApplication.getFileOperations().getToolFilepath();

          trace("file: "+file.url);

      }

       

      private function loadTool(xmlFilepath:File, xmlFilename:String):void

      {

          trace("MyLibraryToolsPanel FUNCTION loadTool("+xmlFilepath.url+", "+xmlFilename+")"); // MyLibraryToolsPanel FUNCTION loadTool(app-storage:/User000000/Tools, 000000Tool1371827886983.xml)

       

          var xmlFile:File = xmlFilepath.resolvePath(xmlFilename);

       

          if(xmlFile.exists)

          {

              fileStream = new FileStream();

              fileStream.open(xmlFile, FileMode.READ);

              toolXML = XML(fileStream.readUTFBytes(fileStream.bytesAvailable));

              fileStream.close();

       

              var obj:Object = new Object();

              obj.xmlFilepath = xmlFilepath;

              obj.xmlFilename = xmlFilename;

              obj.xml = toolXML;

              trace("obj: "+obj); // obj: [object Object]

              // trace("MyLibraryToolsPanel FUNCTION loadTool\n"+obj.xml.toXMLString());   // returns the XML when uncommented

       

              itemArray.addItemAt(obj, itemArray.length);

      }

      else

      {

          trace("MyLibraryToolsPanel FUNCTION loadTool XMLFILE DOES NOT EXIST");  // This never triggers

      }

       

      <s:List id="itemList"

          useVirtualLayout="false"

          changing="listChangingHandler(event)"

          click="event.stopPropagation();"

          touchTap="event.stopPropagation();"

          scrollSnappingMode="leadingEdge"

          height="{height}"

          interactionMode="touch"

          explicitHeight="{height}"

          dropEnabled="false"

          dragEnabled="false"

          dragMoveEnabled="false"

          allowMultipleSelection="false"

          alternatingItemColors="[0xe6e6fa,0xF0F8ff]"

          dataProvider="{itemArray}"

          itemRenderer="renderers.MyLibraryToolsPanelListItemRenderer"

          horizontalScrollPolicy="off"

          verticalScrollPolicy="on"

          borderVisible="false"

          visible="{itemArray.length > 0}"

          includeInLayout="{itemList.visible}"

          width="100%">

       

          <s:layout>

              <s:VerticalLayout id="itemListVerticalLayout" variableRowHeight="false" gap="0"/>

          </s:layout>

      </s:List>

       

       

      <s:Label id="noToolsMsg" text="No saved tools available." horizontalCenter="0" verticalAlign="middle" verticalCenter="0" visible="{itemArray.length == 0}" includeInLayout="{noToolsMsg.visible}"/>

      </s:Group>

       

      === Renderer code containing relevant sections ===

      protected function creationCompleteHandler():void

      {

          trace("MyLibraryToolsPanelListItemRenderer FUNCTION creationCompleteHandler"); // MyLibraryToolsPanelListItemRenderer FUNCTION creationCompleteHandler

          trace("data: "+data);  // data: null

       

          dataProxy = new ObjectProxy(data);

      ...

        • 1. Re: Spark List ItemRenderer 'data' is null.
          Bramblethorne Level 1

          Looks like I'll be changing to using dataChange instead of creationComplete in all my custom item renderers.  I can't believe I lost 2+ days and more hair because of something so trivial as multithreading.

           

          Really... You can't RENDER an item before data is passed and the renderer is ONLY INSTANTIATED once an item is added to the dataProvider.... So... procedure.   Data Added To dataProvider => Insantiate WITH relevant data object => Layout/render/update => THEN creationComplete();   Duh.  creationComplete is a misnomer if you don't even have the relevant data you're using to CREATE the instance.

           

          Probably this would be avoided if the BUG that places the dummy renderer INTO the dataProvider were to be fixed, but as it's -not- been fixed, I've no alternative but to disable virtual layout.   Grouse, grumble, winge winge winge.