0

*Hello there!, I need to populate only 100 items on a dataProvider that is shown in a list component. even if the items are more than 500 or even 1000, I only want 100 items, first all the items with the camera on, and fill the rest to complete 100 in total to be on the DataProvider. Using ActionScript 3.0 (Flash CC):

UPDATE: basically, what I need is: I have a videochat app in flash, so when there are hundreds of users the app becomes slow due to the list component populating hundreds of items(users), so I would like to have at least 100 users on the list giving priority to the users streaming live video. does it make sense? :) thanks – Alex just now edit
*

Code:

function syncEventHandler(event:SyncEvent){
        list1.removeAll();

             for (var i in users_so.data){

                 if (users_so.data[i] != null)
                      {
                          var clientObj = users_so.data[i];
                //if user is streaming add it first then complete 100 with the rest.
                          list1.addItem({label:clientObj.UserName});
                      }


            }
    }

Thank you for taking time for this one!

Alex
  • 25
  • 1
  • 8
  • it depends on where the data comes from ideally, if you pull this data from a server (via GET/a webservice/etc.) the server implementation should provide you with the option of asking for only 100 items to begin with. If that's not an option(you have no control over the server side part), you can have two DataProvider objects. One what will pull the full data(e.g. all 500 or 100) and another which will only store references to 100 entries. Actually, once you pull the data, you can store it into a typed array of value objects and update a single DataProvider with 100 references as you need them – George Profenza Feb 09 '14 at 18:36
  • ...sounds like pagination is what you need – George Profenza Feb 09 '14 at 18:36
  • basically, what I need is: I have a videochat app in flash, so when there are hundreds of users the app becomes slow due to the list component populating hundreds of items(users), so I would like to have at least 100 users on the list giving priority to the users streaming live video. does it make sense? :) thanks – Alex Feb 09 '14 at 20:51
  • makes sense.you probably have a connect/disconnect event when you should add/remove an item from the list(rather than removing and adding all of them). you can use an array to fetch all of them and then add/remove only what changed. I'm guessing the problem is the list component invalidating. On the side try other components (like minimal components) perhaps. Also, in general it's good to keep things separated (using threads/as3 workers) so you don't lock/freeze the UI. Have a look at these video guides([1](http://gotoandlearn.com/play.php?id=162),[2](http://gotoandlearn.com/play.php?id=163)). – George Profenza Feb 09 '14 at 22:04
  • Hi George, actually the users are stored in a remote shared object which is sent to all the swf clients and each client have the function to populate the sharedObject into a list component, I looked for a component to work with this but no luck, also I have no idea on how to do it like just adding the user if it wasn't on the list already or just remove the user that logged off without populating the whole list all the time. Thanks! – Alex Feb 10 '14 at 01:06

1 Answers1

0

I'm not sure of what your intent is but you can limit the number of items in the data provider by implementing a global counter like so:

function syncEventHandler(event:SyncEvent)
{
    list1.removeAll();
    counter = 0;
    for (var i in users_so.data)
    {

        if (users_so.data[i] != null)
        {
             if(counter < 100)
             {
                 var clientObj = users_so.data[i];
                 //if user is streaming add it first then complete 100 with the rest.
                 list1.addItem({label:clientObj.UserName});
                 counter ++;
             }
             else
             {
                 break;
             }
        }

    }
}
  • Hi, I tried your code but some itmes are missing, for example: `if (clientObj.webcamLive == true){ list1.addItem({label:clientObj.UserName}); counter++ }` – Alex Feb 09 '14 at 18:59