Packageimpression.utilities
Classpublic class TreeView
InheritanceTreeView Inheritance flash.display.Sprite

The TreeView class displays a hierarchical view of an XML document.

The TreeView class was designed to support Impression LessonMap objects, but can be used to display any XML document. Each element in the document is given its own node, and a user-specified attribute present in each element is used as the node's text.



Public Properties
 PropertyDefined By
  attributeName : String
[read-only] The name of the attribute in each XML element to use for the associated node's text.
TreeView
  selected : TreeNode
The selected TreeNode.
TreeView
  source : XML
[read-only] The XML object containing the data used to build the TreeView.
TreeView
Public Methods
 MethodDefined By
  
TreeView(scrollPane:* = null)
Creates a new instance of the TreeView class.
TreeView
  
clearNodeStyle(styleName:String, style:String):void
Deletes a TreeNode style property.
TreeView
  
clearStyle(style:String):void
Deletes a style property.
TreeView
  
collapse(node:TreeNode):void
Collapses a TreeNode.
TreeView
  
Collapses all nodes.
TreeView
  
Ensures that a TreeNode is visible.
TreeView
  
expand(node:TreeNode):void
Expands a TreeNode.
TreeView
  
expandAll():void
Expands all nodes.
TreeView
  
getNodeStyle(styleName:String, style:String):Object
Retrieves a TreeNode style property.
TreeView
  
[static] Retrieves the default style map for TreeNode object.
TreeView
  
getStyle(style:String):Object
Retrieves a style property.
TreeView
  
[static] Retrieves the default style map for the treeview.
TreeView
  
loadXML(source:XML, attributeName:String):void
Builds the tree from an XML object.
TreeView
  
nodeOf(source:XML):TreeNode
Returns the TreeNode associated with an XML element.
TreeView
  
redraw():void
Forces a complete redraw of the tree.
TreeView
  
setNodeStyle(styleName:String, style:String, value:Object):void
Sets a TreeNode style property.
TreeView
  
setSize(width:Number, height:Number):void
Sets the object to the specified width and height.
TreeView
  
setStyle(style:String, value:Object):void
Sets a style property.
TreeView
Events
 Event Summary Defined By
  Dispatched when a TreeNode is collapsed.TreeView
  Dispatched when a TreeNode is expanded.TreeView
  Dispatched when an XML object is loaded.TreeView
  Dispatched after a TreeNode is selected.TreeView
  Dispatched before a TreeNode is selected.TreeView
Styles
 Style Description Defined By
  
backgroundAlpha
Type: Number
The alpha transparency value of the TreeView. The default value is 1.0.
TreeView
  
backgroundColor
Type: uint Format: Color
The background color of the TreeView. The default value is 0xFFFFFF.
TreeView
  
collapseIcon
Type: Object
Identifies the icon to use as the collapse element.

This value can be a String or an Object. If the value is a String, the TreeNode will attempt to create a new instance of the class identified by the value. If the value is an Object, the TreeNode will attempt to use it as a display object.

The default value is "treeviewCollapseIcon".
TreeView
  
expandCollapseNodeSpacing
Type: Number Format: Length
The spacing between the right edge of the expand/collapse element and the left edge of a node, in pixels. The default value is 4.
TreeView
  
expandIcon
Type: Object
Identifies the icon to use as the expand element.

This value can be a String or an Object. If the value is a String, the TreeNode will attempt to create a new instance of the class identified by the value. If the value is an Object, the TreeNode will attempt to use it as a display object.

The default value is "treeviewExpandIcon".
TreeView
  
indentation
Type: Number Format: Length
The amount, in pixels, to indent a child node. The default value is 16.
TreeView
  
lineAlpha
Type: Number
The alpha transparency value of the lines. The default value is 1.0.
TreeView
  
lineColor
Type: uint Format: Color
The color of the lines. The default value is 0xCCCCCC.
TreeView
  
lineDashLength
Type: Number Format: Length
Indicates the length of the dash segment of the lines, in pixels. The default value is 2.
TreeView
  
lineGapLength
Type: Number Format: Length
Indicates the length of the gap segment of the lines, in pixels. Set this value to 0 to draw solid lines. The default value is 2.
TreeView
  
lineThickness
Type: Number Format: Length
Indicates the thickness of the lines, in pixels. The default value is 1.
TreeView
  
nodeSpacing
Type: Number Format: Length
The vertical space between nodes, in pixels. The default value is 0.
TreeView
  
padding
Type: Number Format: Length
The padding between the nodes and the edges of the TreeView, in pixels. The default value is 6.
TreeView
  
showExpandCollapse
Type: Boolean
Indicates whether the expand/collapse elements should be shown. The default value is true.
TreeView
  
showLines
Type: Boolean
Indicates whether lines should be drawn between nodes. The default value is false.
TreeView
  
showRootMargin
Type: Boolean
Indicates whether the top-level node or nodes should be indented. The default value is false.
TreeView
  
showXMLRoot
Type: Boolean
Indicates whether a TreeNode for the XML root should be shown. The default value is false.
TreeView
  
showXMLRoot
Type: Boolean
Indicates whether a TreeNode for the XML root should be shown. The default value is false.
TreeView
Property Detail
attributeNameproperty
attributeName:String  [read-only]

The name of the attribute in each XML element to use for the associated node's text.


Implementation
    public function get attributeName():String
selectedproperty 
selected:TreeNode

The selected TreeNode.

When this property is set to a new value, the TreeView dispatches a TreeViewRequestEvent.SELECT_REQUEST event with a reason value of TreeViewEventReasons.CODE.

If the select request event is not cancelled, the event's newNode value is selected, and a TreeViewEvent.SELECT event with a reason value of TreeViewEventReasons.CODE is dispatched.


Implementation
    public function get selected():TreeNode
    public function set selected(value:TreeNode):void

See also

sourceproperty 
source:XML  [read-only]

The XML object containing the data used to build the TreeView.


Implementation
    public function get source():XML
Constructor Detail
TreeView()Constructor
public function TreeView(scrollPane:* = null)

Creates a new instance of the TreeView class.

Parameters
scrollPane:* (default = null) — A ScrollPane or other object that can act as a container for the TreeView content.

Throws
ArgumentError — scrollPane cannot be null (ArgumentError)
Method Detail
clearNodeStyle()method
public function clearNodeStyle(styleName:String, style:String):void

Deletes a TreeNode style property.

If styleName is null or the empty string (""), the style property referenced is the default style property value to use for all nodes. If styleName is not null or the empty string, the style property references is the style property value to use for all nodes with a styleName property value matching the styleName parameter.

The style parameter value should be one of the styles defined in the TreeNode object.

Parameters

styleName:String — The node style name associated with the style.
 
style:String — The name of the style property.

See also

clearStyle()method 
public function clearStyle(style:String):void

Deletes a style property.

Parameters

style:String — The name of the style property.

See also

collapse()method 
public function collapse(node:TreeNode):void

Collapses a TreeNode.

If the node.hasChildren property is false or the node.expand property is false, invoking this method has no effect.

If the node.hasChildren property is false or the node.expand property is false, invoking this method has no effect. If the node was expanded, a TreeViewEvent.COLLAPSE event with a reason value of TreeViewEventReasons.CODE is dispatched.

Parameters

node:TreeNode — The TreeNode to collapse.

See also

collapseAll()method 
public function collapseAll():void

Collapses all nodes.

If any nodes were collapsed, a single TreeViewEvent.COLLAPSE with a reason value of TreeViewEventReasons.CODE is dispatched.

See also

ensureVisible()method 
public function ensureVisible(node:TreeNode):void

Ensures that a TreeNode is visible.

If necessary, this routine will expand any collapsed ancestors of node and adjust the scroll pane so that the node is displayed within the visible area. If any nodes were expanded, a single TreeViewEvent.EXPAND with a reason value of TreeViewEventReasons.CODE is dispatched.

Parameters

node:TreeNode — The TreeNode to ensure the visibility of.

See also

expand()method 
public function expand(node:TreeNode):void

Expands a TreeNode.

If the node.hasChildren property is false or the node.expand property is true, invoking this method has no effect. If the node was expanded, a TreeViewEvent.EXPAND event with a reason value of TreeViewEventReasons.CODE is dispatched.

Parameters

node:TreeNode — The TreeNode to expand.

See also

expandAll()method 
public function expandAll():void

Expands all nodes.

If any nodes were expanded, a single TreeViewEvent.EXPAND with a reason value of TreeViewEventReasons.CODE is dispatched.

See also

getNodeStyle()method 
public function getNodeStyle(styleName:String, style:String):Object

Retrieves a TreeNode style property.

If styleName is null or the empty string (""), the style property referenced is the default style property value to use for all nodes. If styleName is not null or the empty string, the style property referenced is the style property value to use for all nodes with a styleName property value matching the styleName parameter.

The style parameter value should be one of the styles defined in the TreeNode object.

Parameters

styleName:String — The node style name associated with the style.
 
style:String — The name of the style property.

Returns
Object — Style value.

See also

getNodeStyleDefinition()method 
public static function getNodeStyleDefinition():Object

Retrieves the default style map for TreeNode object.

Returns
Object — Default styles object.

See also

getStyle()method 
public function getStyle(style:String):Object

Retrieves a style property.

Parameters

style:String — The name of the style property.

Returns
Object — Style value.

See also

getStyleDefinition()method 
public static function getStyleDefinition():Object

Retrieves the default style map for the treeview.

Returns
Object — Default styles object.

See also

loadXML()method 
public function loadXML(source:XML, attributeName:String):void

Builds the tree from an XML object.

Once the tree is built, this object dispatches a TreeViewRequestEvent.SELECT_REQUEST event with a reason value of TreeViewEventReasons.LOAD_COMPLETE, and values of null for both the oldNode and newNode properties.

If the select request event is not cancelled, the selected node is set to the value of the event's newNode value, and a TreeViewEvent.SELECT event with a reason value of TreeViewEventReasons.LOAD_COMPLETE is dispatched.

Finally, a TreeViewEvent.LOAD_COMPLETE event is dispatched.

Parameters

source:XML — The XML object to build the tree from.
 
attributeName:String — The name of the attribute to use for each node's text.

See also

nodeOf()method 
public function nodeOf(source:XML):TreeNode

Returns the TreeNode associated with an XML element.

If an associated TreeNode cannot be found, the method returns null.

Parameters

source:XML — The XML object to find the node of.

Returns
TreeNode — The TreeNode associated with source.
redraw()method 
public function redraw():void

Forces a complete redraw of the tree.

All nodes are rebuilt from the XML object. If possible, the last node selected will be selected again. Note that no events are dispatched as a result of invoking this method.

setNodeStyle()method 
public function setNodeStyle(styleName:String, style:String, value:Object):void

Sets a TreeNode style property.

If styleName is null or the empty string (""), the style property referenced is the default style property value to use for all nodes. If styleName is not null or the empty string, the style property references is the style property value to use for all nodes with a styleName property value matching the styleName parameter.

The style parameter value should be one of the styles defined in the TreeNode object.

Parameters

styleName:String — The node style name associated with the style.
 
style:String — The name of the style property.
 
value:Object — The value of the style.

See also

setSize()method 
public function setSize(width:Number, height:Number):void

Sets the object to the specified width and height.

This method attempts to invoke the setSize() method on the ScrollPane object. If the object does not support the setSize() method, invoking this method has no effect.

Parameters

width:Number — The width of the object, in pixels.
 
height:Number — The height of the object, in pixels.

setStyle()method 
public function setStyle(style:String, value:Object):void

Sets a style property.

Parameters

style:String — The name of the style property.
 
value:Object — The value of the style.

See also

Event Detail
treeviewCollapse Event
Event Object Type: impression.events.TreeViewEvent
TreeViewEvent.type property = TreeViewEvent.COLLAPSE

Dispatched when a TreeNode is collapsed.

Note that only one collapse event will be dispatched per action, even if the action caused multiple nodes to be collapsed.

See also

treeviewExpand Event  
Event Object Type: impression.events.TreeViewEvent
TreeViewEvent.type property = TreeViewEvent.EXPAND

Dispatched when a TreeNode is expanded.

Note that only one expand event will be dispatched per action, even if the action caused multiple nodes to be expanded.

See also

treeviewLoadComplete Event  
Event Object Type: impression.events.TreeViewEvent
TreeViewEvent.type property = TreeViewEvent.LOAD_COMPLETE

Dispatched when an XML object is loaded.

This event is dispatched after any selection related events.

See also

treeviewSelect Event  
Event Object Type: impression.events.TreeViewEvent
TreeViewEvent.type property = TreeViewEvent.SELECT

Dispatched after a TreeNode is selected.

See also

treeviewSelectRequest Event  
Event Object Type: impression.events.TreeViewRequestEvent
TreeViewRequestEvent.type property = TreeViewRequestEvent.SELECT_REQUEST

Dispatched before a TreeNode is selected.

If this event is cancelled, the node will not be selected. Note that the newNode event property is read-write; changing the newNode event property value will change the node to be selected.

See also