2014-02-09 24 views
0

*您好!我需要在列表組件中顯示的dataProvider上僅填充100個項目。即使物品超過500甚至1000個,我只需要100個物品,首先打開所有物品,然後填充剩下的物品以完成100個物品,然後放置在DataProvider上。 使用ActionScript 3.0(閃存CC):如何限制數據提供者接收到的項目數量AS3

UPDATE:基本上,我需要的是:我有一個視頻聊天應用閃光燈,所以當有數百個用戶的應用由於列表組件填充數百變慢項目(用戶),因此我希望列表中至少有100個用戶優先考慮流式直播視頻的用戶。是否有意義? :)謝謝 - 亞歷剛纔編輯
*

代碼:

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}); 
         } 


      } 
    } 

感謝您抽出寶貴時間,這一個!

+0

這取決於該數據來自理想,如果你從服務器獲取這些數據(通過GET/a webservice/etc),服務器實現應該爲你提供只需要100個項目的選項。如果這不是一個選項(你無法控制服務器端部分),那麼可以有兩個DataProvider對象。一種是提取全部數據(例如全部500或100),另一種只存儲對100個條目的引用。實際上,一旦你拉出數據,你可以將它存儲到一個有價值的對象類型數組中,並在需要時使用100個引用更新一個DataProvider。 –

+0

...聽起來像分頁是你需要的 –

+0

基本上,我需要的是:我在Flash中有一個videochat應用程序,所以當有數百個用戶時,由於list組件填充了數百個項目(用戶),所以應用程序變得很慢,所以我希望列表中至少有100個用戶優先給用戶流媒體直播視頻。是否有意義? :)謝謝 – Alex

回答

0

我不知道你的意圖是什麼,但你可以通過實現像這樣一個全球性的反限制的數據提供者的項目數:

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; 
      } 
     } 

    } 
} 
+0

嗨,我試過你的代碼,但有些缺失,例如: 'if(clientObj.webcamLive == true){list1.addItem({label:clientObj.UserName}); counter ++ }' – Alex

相關問題