Hi,
My situation:
- 1 Tree component (id=tree)
- 1 XMLListCollection as a dataprovider for the tree (id=treeData)
- 1 String, a url, that has to be found & selected.
My XMLListCollection looks like this:
<page title="page1" href="url1">
<page title="subpage1" href="url2"/>
<page title="subpage2" href="url3">
<page title="subsubpage1" href="url4">
</page>
</page>
<page title="page2" href="url5">
<page .../>
<page .../>
</page>
Etc. All nodes are named 'page' and have a href property.
What I need now, is a way to select the node in the tree for the given url. For
example, all nodes are collapsed and I want to select the node with href=url4.
How can I do this?
This is what I tried:
var t:XMLListCollection = this.treeData;
var url:String = "myURL";
for(var i:Number = 0; i<t.length; i++)
{
//this works, nodes now contains a list of xml items with the correct
url.
var nodes:XMLList = t[i]..page.(@href==url);
if(nodes.length() > 0)
{
//I only want to select the first occurence
tree.selectedItem = nodes[0];
break;
}
}
This, however, gives me a weird error (probably not that helpfull):
TypeError: Error #1010: A term is undefined and has no properties.
at
mx.controls.listClasses::ListBase/setSelectionDataLoop()[E:\dev\beta1\frameworks\projects\framework\src\mx\controls\listClasses\ListBase.as:7360]
at
mx.controls.listClasses::ListBase/commitSelectedItems()[E:\dev\beta1\frameworks\projects\framework\src\mx\controls\listClasses\ListBase.as:7251]
at
mx.controls.listClasses::ListBase/commitSelectedItem()[E:\dev\beta1\frameworks\projects\framework\src\mx\controls\listClasses\ListBase.as:7216]
at mx.controls.listClasses::ListBase/set
selectedItem()[E:\dev\beta1\frameworks\projects\framework\src\mx\controls\listClasses\ListBase.as:3474]
at classes::Logic/onBrowserLocationChange()[C:\Users\ser\Documents\Flex
Builder 3\application\src\classes\Logic.as:346]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at
mx.core::UIComponent/dispatchEvent()[E:\dev\beta1\frameworks\projects\framework\src\mx\core\UIComponent.as:11260]
at
Classes::Logic/onBrowserLocationChange()[C:\Users\user\Documents\Flex Builder
3\application\src\classes\Logic.as:73]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at
mx.core::UIComponent/dispatchEvent()[E:\dev\beta1\frameworks\projects\framework\src\mx\core\UIComponent.as:11260]
at
mx.controls::HTML/htmlLoader_locationChangeHandler()[E:\dev\beta1\frameworks\projects\airframework\src\mx\controls\HTML.as:1438]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.html::HTMLLoader/onLocationChangeTimer()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
Greets,
Dauntless