如何向DataGroup发出有关IList Dataprovider中数据更改的信号?

时间:2013-03-15 05:27:01

标签: actionscript-3 flex events flex4.5

我实现IList接口,如

[Bindable]
  public class MemList implements IList
  {
    public function MemList()
    {      
    }    
    public function get length():int
    {
      var size:int = 5000;
      return size;      
    }    
    public function addItem(item:Object):void
    {  
    }    
    public function addItemAt(item:Object, index:int):void
    {    
    }    
    public function getItemAt(index:int, prefetch:int=0):Object
    {      
      var obj:Object = new Object();                       
      obj.value = ByteStr(); // this function return a string
      return obj;      
    }    
    public function getItemIndex(item:Object):int
    {     
      return 0;
    }    
    public function itemUpdated(item:Object, property:Object=null, oldValue:Object=null, newValue:Object=null):void
    {     
    }    
    public function removeAll():void
    {      
    }    
    public function removeItemAt(index:int):Object
    {     
      return null;
    }    
    public function setItemAt(item:Object, index:int):Object
    {     
      return null;
    }    
    public function toArray():Array
    {     
      return null;
    }    
    public function addEventListener(type:String, listener:Function, useCapture:Boolean=false, priority:int=0, useWeakReference:Boolean=false):void
    {
    }    
    public function removeEventListener(type:String, listener:Function, useCapture:Boolean=false):void
    {
    }    
    public function dispatchEvent(event:Event):Boolean
    {
      return false;
    }    
    public function hasEventListener(type:String):Boolean
    {
      return false;
    }    
    public function willTrigger(type:String):Boolean
    {
      return false;
    }
  }

并将其对象提供给DataGroup作为数据提供者,在Mxml文件中我这样做

<fx:Script><![CDATA[

    [Bindable]private var list:MemList = new MemList();

   protected function onBtnShow(event:MouseEvent):void
    {          
      send(somenumber, MAX_SIZE, onShowResp);//get data from network      
    }

    private function onShowResp(retVal:uint, ba:ByteArray):void
    {
      //this function called when ba bytearray is filled with data.
    }        

  ]]></fx:Script>
<s:Button id="btnShow" label="Show" click="onBtnShow(event)"/>
<s:Scroller verticalScrollPolicy="auto" id="aScroller" 
        liveScrolling="false">
        <s:DataGroup id="dgMemView" width="100%" height="350"          
          dataProvider="{list}"
          clipAndEnableScrolling="true"
          itemRenderer="ItemRenderer"
          >        
          <s:layout>
            <s:VerticalLayout useVirtualLayout="true"/>
          </s:layout>        
        </s:DataGroup>
      </s:Scroller>

public function ByteStr(loc:uint):String
    {
      //this function can access ba bytearray filled with data. do some processing 
      on that data and return a string.
      return string;
    }

我的问题是,当应用程序运行数据组没有显示任何内容时,因为ba(bytearray)中没有必须填充网络数据的数据。当我按下show按钮它会发出请求并用数据填充ba(bytearray)。如何通知Datagroup数据已更改。我正在使用Flash builder 4.5。感谢

1 个答案:

答案 0 :(得分:1)