mx.updatedcontrols
class Tree
mx.updatedcontrols.List
|
+--mx.updatedcontrols.Tree
All Known Subclasses: dndTreeclass Tree extends List
Tree class - extends List
Field Summary
branchNodes: Object
An index of branch nodes in the tree
nodeIndices: Object
An index of nodes displayed in the tree
openNodes: Object
A table of nodes that are open
Property Summary
firstVisibleNode (read, write)
Gets or sets the first visible node at the top of the view pane
selectedNode (read, write)
Gets or sets the selected node in the tree
selectedNodes (read, write)
Gets or sets the selected nodes in the tree
Method Summary
addTreeNode (
label, data
)
Appends a child node at the end of the tree node
addTreeNodeAt (
index, label, data
)
Adds a child node at the specified index on the tree node
getDisplayIndex (
node
)
Returns the index of the node specified on the tree's list of displayed nodes
getIsBranch (
node
)
Checks if the specified node is a branch
getIsOpen (
node
)
Returns if the specified node is open or closed
getNodeDepth (
node
)
Returns the depth of the specified node
getNodeDisplayedAt (
index
)
Returns the node specified on the tree's list of displayed nodes
getRootNode (
)
Gets the root node from the tree
getTreeNodeAt (
index
)
Returns the child node at the specified index
isNodeVisible (
node
)
Returns if the node specified is a visible node
refresh (
)
Redraws the displayed nodes
removeAll (
)
Removes all nodes from the tree
removeTreeNodeAt (
index
)
Removes the child node at the specified index
setDisplayIndex (
node, UID
)
setIcon (
node, iconID, iconID2
)
Sets the icon(s) for the specified node
setIsBranch (
node, branch
)
Sets the specified node to be a branch or leaf node (if possible)
setIsOpen (
node, open, animate, fireEvent
)
Opens or closes the specified node
Field Documentation
branchNodes
var branchNodes: Object
An index of branch nodes in the tree
Internal Object; An index of branch nodes in the tree accessable by id. If a node's ID is within the branchNodes table, it's a branch. Use setIsBranch or getIsBranch to explicitly set this. You can also use the labelFunction to specifically and automatically type your nodes on a as needed basis. You would check if an attribute exists or check if childNodes exist (its up to you to determine) and set the node to a leaf or branch. Use setIsBranch(theNode, true) or setIsBranch(theNode, false). Note you cannot set a node to a leaf node type if it has children.
- Usage:myInstance.branchNodes[];
- Example:
The example checks if the selected node is in the branchNodes index.
trace("Is node branch = " + (theTree.branchNodes[theTree.selectedNode.getID()])); - See also:
nodeIndices
var nodeIndices: Object
An index of nodes displayed in the tree
Internal Object; An index of nodes that are displayed in the tree accessable by id. If a node's ID is within the nodeUID table, or nodeIndices list, it's on the displayList.
- Usage:myInstance.nodeIndices[];
- Example:The example checks if the selected node is on the display list.
trace("Is node displayed = " + (theTree.theTree[theTree.selectedNode.getID()])); - See also:
openNodes
var openNodes: Object
A table of nodes that are open
Internal Array; A table of nodes that are open accessable by id. If a node's ID is within the openNodes table, it's open. The dndTree.getIsOpen() method checks this array for you.
- Usage:myInstance.openNodes[];
- Example:The example checks if the selected node is in the openNodes array.
trace("Is node open = " + (theTree.openNodes[theTree.selectedNode.getID()])); - See also:
Property Documentation
firstVisibleNode
firstVisibleNode (read, write)
Gets or sets the first visible node at the top of the view pane
Property; Gets or sets the first visible node at the top of the view pane. Use this property to scroll the tree display to a desired position. If the specified node someNode is within a node that hasn’t been expanded, setting firstVisibleNode has no effect. The default value is the first visible node or undefined if there is no visible node. The value of this property is an XMLNode object. This property is an analogue to the List.vPosition property.
- Value:The first visible XML node
- Usage:myInstance.firstVisibleNode = someNode;
- Example:The following example sets the selected node as the first visible node at the top of the display.
theTree.firstVisibleNode = theTree.selectedNode;
- See also:
selectedNode
selectedNode (read, write)
Gets or sets the selected node in the tree
Property; Gets or sets the selected node in the tree. If the specified node is within a node that hasn’t been expanded, setting selectedNode has no effect.
- Value:The selected XML node or undefined if none is selected.
- Usage:myInstance.selectedNode = someNode;
- Example:The following example gets the selected node.
trace("The node you selected has this xml: " + theTree.selectedNode); - See also:
selectedNodes
selectedNodes (read, write)
Gets or sets the selected nodes in the tree
Property; Gets or sets the selected nodes in the tree. If a specified node within the selectedNodes is hidden in a parent node, setting selectedNodes has no effect on those nodes.
- Value:Object. The selected XML nodes or undefined if none are selected.
- Usage:instance.selectedNodes = someNodes;
- Example:The following example selects the first and third child nodes in the tree if they are visible.
theTree.selectedNodes = [theTree.getTreeNodeAt(0), theTree.getTreeNodeAt(2)];
- See also:
Constructor Documentation
Method Documentation
addTreeNode
function addTreeNode (
label,
data)
data)
Appends a child node at the end of the tree node
Method; Appends a child node at the end of the tree node. The node is constructed either from the information supplied in the label and data parameters (Usage 1), or from the prebuilt child node, which is an XMLNode object (Usage 2). Adding a preexisting node removes the node from its previous location unless the cloneNode function is used. Calling this method refreshes the view.
- Parameters:
label A string that displays the node, or an object with a label field (or whatever label field name is specified by the labelField property). data Optional. An object of any type that is associated with the node. - Returns:The added XML node.
- Usage:addTreeNode(label [, data])addTreeNode(xmlNode)
- See also:
addTreeNodeAt
function addTreeNodeAt (
index,
label,
data)
label,
data)
Adds a child node at the specified index on the tree node
Method; Adds a child node at the specified index on the tree node. The node is constructed either from the information supplied in the label and data parameters (Usage 1), or from the prebuilt child node, which is an XMLNode object (Usage 2). Adding a preexisting node removes the node from its previous location unless the cloneNode function is used. You can also call this method from any existing node in the data provider. Calling this method refreshes the view.
- Parameters:
index The zero-based display index position (among the child nodes) at which the node should be added label A string that displays the node, or an object with a label field (or whatever label field name is specified by the labelField property). data Optional. An object of any type that is associated with the node. - Returns:The added XML node.
- Usage:addTreeNodeAt(index, label [, data])addTreeNodeAt(index, xmlNode)
- Example:The following code adds a new node after the third node of the tree.
// usage 1 theTree.addTreeNodeAt(2, "New Node", 5);
- See also:
getDisplayIndex
function getDisplayIndex (
node)
Returns the index of the node specified on the tree's list of displayed nodes
Method; Returns the index of the node specified on the tree's list of displayed nodes. The display index (nodeIndices) is an array of items that are visible in the tree window. For example, any children of a closed node are not in the display index. The display index starts with 0 and proceeds through the visible items regardless of parent. In other words, the display index is the row number, starting with 0, of the displayed rows. Note: A node's display index changes every time nodes are open or closed and can change when the data provider is updated.
- Parameters:
node The XML node - Returns:the index on the tree's display list
- Usage:myInstance.getDisplayIndex(node)
- Example:The following code gets the display index of the selectedNode.
var theDisplayIndex = theTree.getDisplayIndex(theTree.selectedNode));
getIsBranch
function getIsBranch (
node)
Checks if the specified node is a branch
Method; Checks if the specified node is a branch.
- Parameters:
node the node to inspect - Returns:Boolean. true if a branch, false if not
- Example:The example checks if the selected node is a branch.
trace("Is node a branch? " + theTree.getIsBranch(theTree.selectedNode)); - See also:
getIsOpen
function getIsOpen (
node)
Returns if the specified node is open or closed
Method; Returns if the specified node is open or closed. This checks the openNodes table.
- Parameters:
node the node to inspect - Returns:true if open, false if not
- Example:The example returns if the selected node is open.
trace("Is selected node open? " + theTree.getIsOpen(theTree.selectedNode)); - See also:
getNodeDepth
function getNodeDepth (
node)
Returns the depth of the specified node
Method; Returns the depth or generation of the specified node. You could also say it returns how many parents the specified node has.
- Parameters:
node the node to inspect - Example:The example gets the depth of the selected node.
trace("What is the depth of the selected node? " + theTree.getNodeDepth(theTree.selectedNode));
getNodeDisplayedAt
function getNodeDisplayedAt (
index)
Returns the node specified on the tree's list of displayed nodes
Method; Returns the node specified on the tree's list of displayed nodes.
The display index is an array of items that can be viewed in the tree window. For example, any children of a closed node are not in the display index. The display index starts with 0 and proceeds through the visible items regardless of parent. In other words, the display index is the index of the displayed rows.
Note: A nodes display index changes every time a node is opened and closed or the view is scrolled up or down.
- Parameters:
index The zero-based index position of visible nodes in the tree - Returns:The XML node.
- Usage:myInstance.getNodeDisplayedAt(index)
- Example:The following code gets the second visible node.
var secondNode = theTree.getNodeDisplayedAt(1);
getRootNode
function getRootNode (
)
Gets the root node from the tree
Gets the root node from the tree.
- Returns:rootNode
- Usage:myInstance.getRootNode();
- Example:The following code gets the root node from the tree.
var rootNode = theTree.getRootNode();
getTreeNodeAt
function getTreeNodeAt (
index)
Returns the child node at the specified index
Method; Returns the child node at the specified index on the root tree node. You can also call this method from any existing node in the data provider.
- Parameters:
index The zero-based display index position (among the child nodes) - Returns:The added XML node.
- Usage:myInstance.getTreeNodeAt(index)
- Example:The following code gets the second node in the root nodes.
var secondNode = theTree.getTreeNodeAt(1);
isNodeVisible
function isNodeVisible (
node)
Returns if the node specified is a visible node
Method; Returns if the node specified is a visible node. The display index (nodeIndices) is an array of items that are visible in the tree window. For example, any children of a closed node are not in the display index. The display index starts with 0 and proceeds through the visible items regardless of parent. In other words, the display index is the row number, starting with 0, of the displayed rows.
Note: A node's display index changes every time nodes are open or closed and can change when the data provider is updated.
- Parameters:
node The XML node - Returns:The XML node.
- Usage:myInstance.isNodeVisible(node)
- Example:The following code checks if the first child of the first child of the root node is visible.
trace("Is this node visible? " + theTree.isNodeVisible(theTree.dataProvider.firstChild.firstChild));
refresh
function refresh (
)
Redraws the displayed nodes
Method; Redraws the displayed nodes.
- Example:The example refreshes the tree.
theTree.refresh();
removeAll
function removeAll (
)
Removes all nodes from the tree
Method; Removes all nodes from the tree. Calling this method refreshes the view.
- Overrides:mx.updatedcontrols.listclasses.ScrollSelectList.removeAll in class mx.updatedcontrols.listclasses.ScrollSelectList
- Returns:nothing
- Usage:myInstance.removeAll()
- Example:The following code removes all the nodes in the tree.
theTree.removeAll();
removeTreeNodeAt
function removeTreeNodeAt (
index)
Removes the child node at the specified index
Method; Removes the child node at the specified index on the root tree node. You can also call this method from any existing node in the data provider. Calling this method refreshes the view.
- Parameters:
index The zero-based index position (among the child nodes) - Returns:The removed XML node, or undefined if an error occurs.
- Usage:myInstance.removeTreeNodeAt(index)
- Example:The following code removes the second node in the root tree node.
var removedNode = theTree.getTreeNodeAt(1);
setIcon
function setIcon (
node,
iconID,
iconID2)
iconID,
iconID2)
Sets the icon(s) for the specified node
Method; A function to cut node(s) from the tree. A cutNode event is generated when this method is called. The event contains the target which is a reference to the tree and the eventSource, which indicates if the method was called from the context menu. You should use the iconFunction instead of this method if you do any sort of cross drag and drop. To load in and use an external dynamic icon see the code in the dynamic image example included.
- Parameters:
node the node to affect iconID the linkage ID for the closed (or leaf) icon iconID2 the linkage ID for the open (or leaf) icon - Example:
The example below sets the icon(s) for the selected node.
theTree.setIcon(theTree.selectedNode, icon1_mc, icon2_mc);
- See also:
setIsBranch
function setIsBranch (
node,
branch)
branch)
Sets the specified node to be a branch or leaf node (if possible)
Method; Sets the specified node to be a branch even if node has no children. It will also set a branch node to a leaf node if possible (if it has no children). A branch node can be thought of as a type of node that has a folder icon, an expander arrow (disclosure icon) and either has children or can have children. A node is automatically set as a branch when it has children. You only need to call setIsBranch() when you want to create or preserve an empty folder. You may want to create branches that don’t yet have children if, for example, you only want child nodes to load when a user opens a folder. You can use the labelFunction to specifically and automatically type your nodes on a as needed basis. The labelFunction is called when a row is drawn. You would check if an attribute exists or check if childNodes exist (its up to you to determine) and set the node to a leaf or branch. Use setIsBranch(theNode, true) or setIsBranch(theNode, false). Note you cannot set a node to a leaf node type if it has children. You can also use the preserveBranches property to keep branches as branches when the last child node is moved or cut out.
- Parameters:
node The node to affect branch Set to true to explicitly set node to branch. Set to false to clear a branch from the branchNodes table. - Example:The example sets the selected node to a branch.
theTree.setIsBranch(theTree.selectedNode, true);
- See also:
setIsOpen
function setIsOpen (
node,
open,
animate,
fireEvent)
open,
animate,
fireEvent)
Opens or closes the specified node
Method; Opens or closes the specified node. This adds the specified node to the openNodes table.
- Parameters:
node The node to open or close. open Set true to open, false to close. animate Optional. Set true to animate the transition, false to not. fireEvent Optional. Set true to dispatch open or close event. - Example:The example opens the selected node.
theTree.setIsOpen(theTree.selectedNode, true);
- See also:
- Tree.as, Last Modified: 5/18/2006 5:30:00 PM