10 Replies Latest reply: Jun 25, 2012 5:22 AM by sinious RSS

    Cannot get more than 8 item in list component

    logonsuresh Community Member

      Hi,

       

      I can't get more than 8 items in list component using getItemAt(), it returns null. I will search more for this but no result.

      Please Help me here to move to next step.

       

      Thanks

      Sureshkumar G

        • 1. Re: Cannot get more than 8 item in list component
          Ned Murphy CommunityMVP

          Show the code that is giving you problems and explain the intentions of it.

          • 2. Re: Cannot get more than 8 item in list component
            logonsuresh Community Member

            var dP:DataProvider = new DataProvider();

             

            for (var i:int; i<XML_length; i++)

                                          {

                   dP.addItem( { label:String(XMLCoreData.slide.@name[i]), data:XMLCoreData.slide.@path[i] } )

              }

             

              listDrop.dataProvider = dP;

             

             

             

             

            for(var i:int; i<listLength; i++)

                                          {

                 var cr:CellRenderer = _menuList.listDrop.itemToCellRenderer(_menuList.listDrop.getItemAt(i)) as CellRenderer;

                 var listData:ListData = cr.listData;

                 cr.enabled  = false;

                                          }

            • 3. Re: Cannot get more than 8 item in list component
              Ned Murphy CommunityMVP

              I don't see how the second half of that code relates to the first half and you have not explained anything about it. 

               

              After the line:

               

              listDrop.dataProvider = dP;

               

              Whichever component you have that is named listDrop in that scope should have as many items in it as were provided by the data source.  Any code after that has no relationship to the listDrop component if it is in the same scope.

              • 4. Re: Cannot get more than 8 item in list component
                sinious Community Member

                It appears they put the listDrop in _menuList as you see _menuList.listDrop.

                 

                Here's a full example I just posted, slightly modified for this thread, of a list component being created, adding 50 items and selecting 2 items. Item #5 and #35. 35 is certainly past 8 so open a new as3 document and paste this in the frame script. If both traces work, the list component isn't your issue:

                 

                import fl.controls.List;

                import fl.data.DataProvider;

                import flash.events.Event;

                 

                // make a quick dataprovider with 50 items

                var dp:DataProvider = new DataProvider();

                for (var i:int = 0; i < 50; i++)

                {

                          dp.addItem({label:"item "+i,value:i});

                }

                 

                // make list control

                var myList:List = new List();

                addChild(myList);

                myList.setSize(100,300);

                myList.dataProvider = dp;

                 

                // wait for frame to be drawn before accessing

                addEventListener(Event.ENTER_FRAME, handleAddedToStage);

                 

                function handleAddedToStage(e:Event):void

                {

                          removeEventListener(Event.ENTER_FRAME, handleAddedToStage);

                 

                          // traces item 5

                          trace("Item: " + myList.getItemAt(5).label);

                 

                          // traces item 35

                          trace("Item: " + myList.getItemAt(35).label);

                }

                 

                It's probably the data you're inserting. Just try a trace() on the XML and make sure it's what you expect.

                • 5. Re: Cannot get more than 8 item in list component
                  logonsuresh Community Member

                  your sample is working fine, but problem when disable the selected item it returns null.

                  When increasing the rowCount to view all item without scrollbar it works.

                   

                  What to do, Pls help me in this stage.

                  • 6. Re: Cannot get more than 8 item in list component
                    sinious Community Member

                    Show me the code you're using to disable the item. AFAIK you can't disable.

                    • 7. Re: Cannot get more than 8 item in list component
                      logonsuresh Community Member

                           var cr:CellRenderer = _menuList.listDrop.itemToCellRenderer(_menuList.listDrop.getItemAt(selectedIndex) ) as CellRenderer;

                           var listData:ListData = cr.listData;

                           cr.enabled  = false;

                      • 8. Re: Cannot get more than 8 item in list component
                        sinious Community Member

                        I believe you've found a glorified bug. I'd submit this to:

                         

                        https://bugbase.adobe.com/

                         

                        If I disable a visible item it works. If it isn't visible I get: TypeError: Error #1009: Cannot access a property or method of a null object reference.

                         

                        On my own list I did it to a currently visible item:

                         

                        CellRenderer(myList.itemToCellRenderer(myList.getItemAt(2))).enabled = false; // works fine

                         

                        I then did it to an item out of view:

                         

                        CellRenderer(myList.itemToCellRenderer(myList.getItemAt(35))).enabled = false; // error

                         

                        Even if I invalidateItemAt() that index to force a draw or make sure I drawNow() and add a 2 second wait to be absolutely sure the list is drawn and ready to be used, it errors.

                         

                        You could probably scroll to the item, disable, then scroll back where you were before, but that should be unnecessary.

                        • 9. Re: Cannot get more than 8 item in list component
                          logonsuresh Community Member

                          Is there any way to change the color of the item?

                          • 10. Re: Cannot get more than 8 item in list component
                            sinious Community Member

                            If you're asking if you can overall, yes you can:

                             

                            http://help.adobe.com/en_US/as3/components/WS5b3ccc516d4fbf351e63e3d118a9c65b32-7f41.html

                             

                            If you're asking if you can do this in the same context, off-screen, no you still get the same error as the .enabled property.

                             

                            I hate to throw a hunch but I feel as though Adobe is employing something I'm used to in native iOS programming (Apple Devices). In lists they have something called "dequeue". It's the reason an extremely long list scrolls smoothly. What it does is render ONLY the rows that are in view. When a row is about to scroll off view it deallocates it from memory and then recreates the next row. They do this so you only ever have the current amount of viewable rows in memory and it speeds up scrolling. Although, I can make property changes to items in an iOS list that's off-screen so they don't have this issue ;(.  Just food for thought.

                             

                            I'd submit it to the bugbase and see what Adobe states. They may say they intend you to get the item in view, alter it and then go back to your previous position. That would be silly but at most I can tell you I definitely get errors trying to access an element outside my view. They're probably not used to items needing visual toggles when you can't even see them.

                             

                            edit:

                             

                            On a further note I tried the scrollToIndex() method, tried to disable, that much worked fine. The second I then scrolled back to the previously selected index the list screwed up.

                             

                            I even daisy chained functions a second apart (30 frames worth of wait). I scrolled down and that worked so I waited 1 second. I disabled the visible item I wanted to and that worked so I waited another second. I scrollToIndex(0) to get back to the top of the list, the list blew up. Random items (several items) were disabled and the one that I explicitly disabled was enabled.