////////////////////////////////////////////////////////////////////////////////
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////
package mx.collections
{
import flash.utils.IDataInput;
import flash.utils.IDataOutput;
import flash.utils.IExternalizable;
import mx.core.mx_internal;
use namespace mx_internal;
[DefaultProperty("source")]
[RemoteClass(alias="flex.messaging.io.ArrayCollection")]
/**
* The ArrayCollection class is a wrapper class that exposes an Array as
* a collection that can be accessed and manipulated using the methods
* and properties of the ICollectionView
or IList
* interfaces. Operations on a ArrayCollection instance modify the data source;
* for example, if you use the removeItemAt()
method on an
* ArrayCollection, you remove the item from the underlying Array.
*
* @mxml
*
*
The <mx:ArrayCollection>
tag inherits all the attributes of its
* superclass, and adds the following attributes:
* <mx:ArrayCollection * Properties * source="null" * /> ** * @example The following code creates a simple ArrayCollection object that * accesses and manipulates an array with a single Object element. * It retrieves the element using the IList interface
getItemAt
* method and an IViewCursor object that it obtains using the ICollectionView
* createCursor
method.
* * var myCollection:ArrayCollection = new ArrayCollection([ { first: 'Matt', last: 'Matthews' } ]); * var myCursor:IViewCursor = myCollection.createCursor(); * var firstItem:Object = myCollection.getItemAt(0); * var firstItemFromCursor:Object = myCursor.current; * if (firstItem == firstItemFromCursor) * doCelebration(); ** * @langversion 3.0 * @playerversion Flash 9 * @playerversion AIR 1.1 * @productversion Flex 3 */ public class ArrayCollection extends ListCollectionView implements IExternalizable { include "../core/Version.as"; //-------------------------------------------------------------------------- // // Constructor // //-------------------------------------------------------------------------- /** * Constructor. * *
Creates a new ArrayCollection using the specified source array. * If no array is specified an empty array will be used.
* * @param source The source Array. * * @langversion 3.0 * @playerversion Flash 9 * @playerversion AIR 1.1 * @productversion Flex 3 */ public function ArrayCollection(source:Array = null) { super(); this.source = source; } //-------------------------------------------------------------------------- // // Properties // //-------------------------------------------------------------------------- //---------------------------------- // source //---------------------------------- [Inspectable(category="General", arrayType="Object")] [Bindable("listChanged")] //superclass will fire this /** * The source of data in the ArrayCollection. * The ArrayCollection object does not represent any changes that you make * directly to the source array. Always use * the ICollectionView or IList methods to modify the collection. * * @langversion 3.0 * @playerversion Flash 9 * @playerversion AIR 1.1 * @productversion Flex 3 */ public function get source():Array { if (list && (list is ArrayList)) { return ArrayList(list).source; } return null; } /** * @private */ public function set source(s:Array):void { list = new ArrayList(s); } //-------------------------------------------------------------------------- // // Methods // //-------------------------------------------------------------------------- /** * @private * Ensures that only the source property is serialized. */ public function readExternal(input:IDataInput):void { if (list is IExternalizable) IExternalizable(list).readExternal(input); else source = input.readObject() as Array; } /** * @private * Ensures that only the source property is serialized. */ public function writeExternal(output:IDataOutput):void { if (list is IExternalizable) IExternalizable(list).writeExternal(output); else output.writeObject(source); } } }