mx.collections

# HierarchicalCollectionView - AS3 Flex

Package | mx.collections
Class | public class HierarchicalCollectionView
Inheritance | HierarchicalCollectionView EventDispatcher Object
Implements | IHierarchicalCollectionView, IXMLNotifiable

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

The HierarchicalCollectionView class provides a hierarchical view of a standard collection.

MXML Syntax Show MXML Syntax
Hide MXML Syntax
The `<mx.HierarchicalCollectionView>` inherits all the tag attributes of its superclass, and defines the following tag attributes:

      <mx:HierarchicalCollectionView
      Properties
        showRoot="true|false"
        source="No default"
      />

Public Properties
Hide Inherited Public Properties
Show Inherited Public Properties

| Property | Defined By
--- | --- | ---
|  | constructor : Object A reference to the class object or constructor function for a given object instance. | Object
|  | hasRoot : Boolean [read-only] A flag that, if true, indicates that the current data provider has a root node; for example, a single top-level node in a hierarchical structure. | HierarchicalCollectionView
|  | length : int [read-only] The length of the currently parsed collection. | HierarchicalCollectionView
|  | openNodes : Object An Array of Objects containing the data provider element for all the open branch nodes of the data. | HierarchicalCollectionView
|  | showRoot : Boolean A Boolean flag that specifies whether to display the data provider's root node. | HierarchicalCollectionView
|  | source : IHierarchicalData The source data of the IHierarchicalCollectionView. | HierarchicalCollectionView

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined By
--- | --- | ---
|  | HierarchicalCollectionView(hierarchicalData:IHierarchicalData = null, argOpenNodes:Object = null) Constructor. | HierarchicalCollectionView
|  | addChild(parent:Object, newChild:Object):Boolean Adds a child node to a node of the data. | HierarchicalCollectionView
|  | addChildAt(parent:Object, newChild:Object, index:int):Boolean Add a child node to a node at the specified index. | HierarchicalCollectionView
|  | addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void Registers an event listener object with an EventDispatcher object so that the listener receives notification of an event. | EventDispatcher
|  | closeNode(node:Object):void Closes a node to hide its children. | HierarchicalCollectionView
|  | contains(item:Object):Boolean Checks the collection for the data item using standard equality test. | HierarchicalCollectionView
|  | createCursor():IViewCursor Returns a new instance of a view iterator over the items in this view. | HierarchicalCollectionView
|  | dispatchEvent(event:Event):Boolean Dispatches an event into the event flow. | EventDispatcher
|  | getChildren(node:Object):ICollectionView Returns a collection of children, if they exist. | HierarchicalCollectionView
|  | getNodeDepth(node:Object):int Returns the depth of the node in the collection. | HierarchicalCollectionView
|  | getParentItem(node:Object):* Returns the parent of a node. | HierarchicalCollectionView
|  | hasEventListener(type:String):Boolean Checks whether the EventDispatcher object has any listeners registered for a specific type of event. | EventDispatcher
|  | hasOwnProperty(name:String):Boolean Indicates whether an object has a specified property defined. | Object
|  | isPrototypeOf(theClass:Object):Boolean Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter. | Object
|  | openNode(node:Object):void Opens a node to display its children. | HierarchicalCollectionView
|  | propertyIsEnumerable(name:String):Boolean Indicates whether the specified property exists and is enumerable. | Object
|  | refresh():Boolean Applies the sort and filter to the view. | HierarchicalCollectionView
|  | removeChild(parent:Object, child:Object):Boolean Removes the child node from the parent node. | HierarchicalCollectionView
|  | removeChildAt(parent:Object, index:int):Boolean Removes the child node from a node at the specified index. | HierarchicalCollectionView
|  | removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void Removes a listener from the EventDispatcher object. | EventDispatcher
|  | setPropertyIsEnumerable(name:String, isEnum:Boolean = true):void Sets the availability of a dynamic property for loop operations. | Object
|  | toLocaleString():String Returns the string representation of this object, formatted according to locale-specific conventions. | Object
|  | toString():String Returns the string representation of the specified object. | Object
|  | valueOf():Object Returns the primitive value of the specified object. | Object
|  | willTrigger(type:String):Boolean Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type. | EventDispatcher

Events
Click for more information on events
Hide Inherited Events
Show Inherited Events

| Event | Summary | Defined By
--- | --- | --- | ---
|  | activate | [broadcast event] Dispatched when the Flash Player or AIR application gains operating system focus and becomes active. | EventDispatcher
|  | deactivate | [broadcast event] Dispatched when the Flash Player or AIR application operating loses system focus and is becoming inactive. | EventDispatcher

Property Detail

### hasRoot

property

`hasRoot:Boolean` [read-only]

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

A flag that, if `true`, indicates that the current data provider has a root node; for example, a single top-level node in a hierarchical structure. XML and Object are examples of data types that have a root node, while Lists and Arrays do not.

Implementation
`public function get hasRoot():Boolean`

### length

property

`length:int` [read-only]

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

The length of the currently parsed collection.

Implementation
`public function get length():int`

### openNodes

property

`openNodes:Object`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

An Array of Objects containing the data provider element for all the open branch nodes of the data.

Implementation
`public function get openNodes():Object`
`public function set openNodes(value:Object):void`

### showRoot

property

`showRoot:Boolean`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

A Boolean flag that specifies whether to display the data provider's root node. If the source data has a root node, and this property is set to `false`, the collection will not include the root item. Only the descendants of the root item will be included in the collection.

This property has no effect on a source with no root node, such as List and Array objects.

The default value is `true.`

This property can be used as the source for data binding. When this property is modified, it dispatches the `propertyChange` event.

Implementation
`public function get showRoot():Boolean`
`public function set showRoot(value:Boolean):void`

### source

property

`source:IHierarchicalData`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

The source data of the IHierarchicalCollectionView.

Implementation
`public function get source():IHierarchicalData`
`public function set source(value:IHierarchicalData):void`
Constructor Detail

### HierarchicalCollectionView

()
Constructor

`public function HierarchicalCollectionView(hierarchicalData:IHierarchicalData = null, argOpenNodes:Object = null)`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Constructor.

Parameters

| `hierarchicalData:IHierarchicalData` (default = `null`)`` — The data structure containing the hierarchical data.
| `argOpenNodes:Object` (default = `null`)`` — The Object that defines a node to appear as open.

Method Detail

### addChild

()
method

`public function addChild(parent:Object, newChild:Object):Boolean`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Adds a child node to a node of the data.

Parameters

| `parent:Object` — The Object that defines the parent node.
| `newChild:Object` — The Object that defines the new node.

Returns

| `Boolean` — `true` if the node is added successfully.

### addChildAt

()
method

`public function addChildAt(parent:Object, newChild:Object, index:int):Boolean`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Add a child node to a node at the specified index. This implementation does the following:

- If the `parent` is null or undefined, inserts the `child` at the specified `index` in the collection specified by `source`.
- If the `parent` has a `children` field or property, the method adds the `child` to it at the `index` location. In this case, the `source` is not required.
- If the `parent` does not have a `children` field or property, the method adds the `children` to the `parent`. The method then adds the `child` to the parent at the `index` location. In this case, the `source` is not required.
- If the `index` value is greater than the collection length or number of children in the parent, adds the object as the last child.

Parameters

| `parent:Object` — The Object that defines the parent node.
| `newChild:Object` — The Object that defines the child node.
| `index:int` — The 0-based index of where to insert the child node.

Returns

| `Boolean` — `true` if the child is added successfully.

### closeNode

()
method

`public function closeNode(node:Object):void`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Closes a node to hide its children.

Parameters

| `node:Object` — The Object that defines the node.

### contains

()
method

`public function contains(item:Object):Boolean`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Checks the collection for the data item using standard equality test.

Parameters

| `item:Object` — The Object that defines the node to look for.

Returns

| `Boolean` — `true` if the data item is in the collection, and `false` if not.

### createCursor

()
method

`public function createCursor():IViewCursor`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Returns a new instance of a view iterator over the items in this view.

Returns

| `IViewCursor` — IViewCursor instance.

Related API Elements

mx.utils.IViewCursor

### getChildren

()
method

`public function getChildren(node:Object):ICollectionView`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Returns a collection of children, if they exist.

Parameters

| `node:Object` — The Object that defines the node. If `null`, return a collection of top level nodes.

Returns

| `ICollectionView` — ICollectionView instance containing the child nodes.

### getNodeDepth

()
method

`public function getNodeDepth(node:Object):int`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Returns the depth of the node in the collection.

Parameters

| `node:Object` — The Object that defines the node.

Returns

| `int` — The depth of the node.

### getParentItem

()
method

`public function getParentItem(node:Object):*`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Returns the parent of a node. The parent of a top-level node is `null`.

Parameters

| `node:Object` — The Object that defines the node.

Returns

| `*` — The parent node containing the node, `null` for a top-level node, and `undefined` if the parent cannot be determined.

### openNode

()
method

`public function openNode(node:Object):void`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Opens a node to display its children.

Parameters

| `node:Object` — The Object that defines the node.

### refresh

()
method

`public function refresh():Boolean`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Applies the sort and filter to the view. The ICollectionView does not detect changes to a sort or filter automatically, so you must call the `refresh()` method to update the view after setting the `sort` or `filterFunction` property. If your ICollectionView implementation also implements the IMXMLObject interface, you should to call the `refresh()` method from your `initialized()` method.

Returns `true` if the refresh was successful and `false` if the sort is not yet complete (e.g., items are still pending). A client of the view should wait for a CollectionEvent event with the `CollectionEventKind.REFRESH` `kind` property to ensure that the `refresh()` operation is complete.

Returns

| `Boolean` — `true` if the refresh() was complete, `false` if the refresh() is incomplete.

### removeChild

()
method

`public function removeChild(parent:Object, child:Object):Boolean`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Removes the child node from the parent node.

Parameters

| `parent:Object` — The Object that defines the parent node, and `null` for top-level nodes.
| `child:Object` — The Object that defines the child node to be removed.

Returns

| `Boolean` — `true` if the node is removed successfully.

### removeChildAt

()
method

`public function removeChildAt(parent:Object, index:int):Boolean`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Removes the child node from a node at the specified index.

Parameters

| `parent:Object` — The Object that defines the parent node.
| `index:int` — The 0-based index of the child node to remove relative to the parent.

Returns

| `Boolean` — `true` if the child is removed successfully.

© 2015 Adobe Systems Incorporated. All rights reserved.
Mon Apr 10 2017, 12:28 PM -07:00