Показать сообщение отдельно
Старый 11.10.2011, 22:17
surlac вне форума Посмотреть профиль Отправить личное сообщение для surlac Найти все сообщения от surlac
  № 9  
Ответить с цитированием
surlac
 
Аватар для surlac

блогер
Регистрация: Nov 2010
Сообщений: 143
Записей в блоге: 1
Цитата:
Сообщение от in4core Посмотреть сообщение
Подскажите как лучше всего организовать
Можно через итератор, задаешь текущий элемент, шаг и перебираешь структуру. Если нужно забить первое поле каждым третьим сообщением, создаешь следующее:

Код AS3:
var iterator:Iterator = new ItemsIterator();
iterator.listItems = itemsArray; // pre-initialized array of Items
iterator.step = 3;
iterator.current = 0;
var item:Item = iterator.firstItem()
while(!iterator.isDone()){
    iterator.nextItem();
}
ItemsIterator:
Код AS3:
public class ItemsIterator { //todo: Implement Iterator interface 
 
    private var listItems:Array /*of Item*/;
    private var current:int = 0;  
    private var step:int = 1;  
 
    public function nextItem():Item {  
      Item item = null; 
      current += step; 
      if (!isDone()) { 
        item = (Item) listItems[current]; 
      } 
      return item; 
    } 
 
    public function previousItem():Item { 
      Item item = null; 
      current -= step; 
      if (!isDone()) { 
        item = (Item) listItems[current]; 
      } 
      return item; 
    } 
 
    public function firstItem():Item { 
      current = 0; 
      return (Item) listItems[current]; 
    } 
 
    public function lastItem():Item { 
      current = listItems.length - 1; 
      return (Item) listItems[current]; 
    } 
 
    public function isDone():Boolean { 
      return current >= listItems.length ? true : false; 
    } 
 
    public function currentItem():Item { 
      if (!isDone()) { 
        return (Item) listItems[current]; 
      } else { 
        return null; 
      } 
    } 
 
    public function set step(int value):void  { 
      this.step = value; 
    } 
 
    public function set current(int value):void  { 
      this.current= value; 
    } 
 
    //todo: public getters/setters for listItems
 
 }