array 与 arrayCollection

arrayCollection比array高级。增加了一些事件和方法。

而array没有任何事件。所以如果让他们都作为数据源的话,比如:http://tonylian.iteye.com/blog/288964 所谈到的

 

<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> 
      <mx:Script> 
          <![CDATA[ 
              import mx.collections.ArrayCollection; 
              [Bindable] 
              public var myArray:Array=["北京","上海","深圳"]; 
              [Bindable] 
              public var myCollection:ArrayCollection=new ArrayCollection(myArray); 
              public function addCountryToArray(country:String):void{ 
                  myArray.push(country); 
              } 
              public function addCountryToCollection(country:String):void{ 
                  myCollection.addItem(country); 
              } 
          ]]> 
      </mx:Script> 
      <mx:TextInput id="countryTextInput" text="广州"/> 
      <mx:Label text="Bound to Array (Raw Object)"/> 
      <mx:Button click="addCountryToArray(countryTextInput.text)" label="Add Country to Array"/> 
      <mx:List dataProvider="{myArray}" width="200"/> 
      <mx:Label text="Bound to Collection"/> 
      <mx:Button click="addCountryToCollection(countryTextInput.text)" label="Add Country to Collection"/> 
      <mx:List dataProvider="{myCollection}" width="200"/> 
</mx:Application> 

 为什么myArray改变了,视图没有更新?

那是因为array没有事件,它的数据的变化,不会发出任何事件。所以list就没有收到任何消息,也就不会作出改变。

除非你改变myArray指向的对象,这样list就会得到通知,而作出改变。

也就是这样:

public function addCountryToArray(country:String):void{ 
                  myArray=New Array("北京","上海","深圳","广州");} 

 

你可能感兴趣的:(xml,Blog,Adobe)