I currently have a tree that will hit a webservice when you click to expand a node. It works great! My problem is that I'm trying to implement this in an app using the Cairngorm framework and I'm hitting a road block... I want to write a method that will search the tree for a node. Keeping in mind that the tree is not all there since I build it dynamically, my webservice for the search returns the nodes that have to be expanded to find the item. So i need to call the method to expand the tree from within the framework and I don't know how to do this. Here's some code:
here's the code from the view with the tree: <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" xmlns:component="com.testapp.web.component.*" creationComplete="initApp();" xmlns:facility="com.testapp.web.view.facility.*"> <mx:Script> <![CDATA[ import com.adobe.cairngorm.control.CairngormEventDispatcher; import com.testapp.web.model.AppModelLocator; import mx.events.TreeEvent; import mx.rpc.events.FaultEvent; import mx.rpc.events.ResultEvent; import mx.controls.Alert; import com.testapp.web.component.FacilityTreeDataDescriptor; [Bindable] public var model:AppModelLocator = AppModelLocator.getInstance(); /** * Handles the creationComplete event for the application. * * Expects a comma-separated list of folder IDs representing the * initial expansion path for the explorer. **/ private function initApp():void { var token:Object = facility.getTreeXML.send(model.user.token, model.user.rootnode, model.user.display); } /** * Handles the itemOpening event (clicking the expand arrow next to a * directory) for the explorer tree. * * Initiates retrieval of a list of subdirectories from the server and * cancels immediate opening if user is selecting this directory for * the first time. The explorer then opens the directory after * receiving the server response and adding the subdirectories to the * tree. **/ private function loadChildFolders(e:TreeEvent):void { var node:XML = e.item as XML; if (! loadChildFolderNode(node, e.type)) { e.stopPropagation(); e.preventDefault() } } /** * Checks if a tree node is loaded and initiates retrieval if not. **/ private function loadChildFolderNode(node:XML, eventType:String):Boolean { if ([EMAIL PROTECTED] && node.children().length() == 0) { var parameters:Object = {folderID:[EMAIL PROTECTED]; var token:Object = facility.getTreeXML.send(model.user.token, [EMAIL PROTECTED], model.user.display); token.parent = node; token.eventType = eventType; return false; } else { return true; } } /** * Handles the result event for folderService by inserting * subdirectories into the tree under the parent node and then * expanding the tree to display the newly inserted nodes. * * Initiates retrieval of the next level in the starting expansion * path if appropriate. **/ private function addFolders(e:ResultEvent):void { var node:XML = XML(e.result..result); var parent:XML = e.token.parent; if (! parent) { // insert root node here to work around apparent problem with // showRoot property of the Tree component parent = folderData = <getTreeXMLResult></ getTreeXMLResult>; } // add nodes from server response for each (var child:XML in node.children()) { parent.appendChild(child); } facilityTree.expandItem(parent, true, true); // only update tree selection for change events if (facilityTree.selectedItem != parent && e.token.eventType == "change") { facilityTree.selectedItem = parent; } // expandIDs tracks the expansion path var expandIDs:Array = e.token.expandIDs; if (expandIDs != null && expandIDs.length > 0) { var folderID:String = expandIDs.shift(); var list:XMLList = parent.folder.(@id == folderID); if (list.length() > 0) { var parameters:Object = {folderID:folderID}; var token:Object = facility.folderService.send(parameters); token.expandIDs = expandIDs; token.parent = list[0]; token.eventType = (expandIDs.length > 1) ? "init" : "change"; } } } public function facilityClick(e:Event):void { //Alert.show(model.SelectedFacility.placeCode); var event:GetPlaceGeneralEvent = new GetPlaceGeneralEvent ([EMAIL PROTECTED]); CairngormEventDispatcher.getInstance().dispatchEvent(event); var event1:GetPlaceGeneralChartEvent = new GetPlaceGeneralChartEvent([EMAIL PROTECTED]); CairngormEventDispatcher.getInstance().dispatchEvent(event1); } ]]> </mx:Script> <mx:WebService id="facility" showBusyCursor="true" wsdl="http:// webtest.testapp.com/xml_provider/facility.asmx?WSDL"> <mx:operation name="getTreeXML" resultFormat="e4x" fault="handleFault (event)" result="addFolders(event)" > <mx:request> <webToken></webToken> <placeID></placeID> <label></label> </mx:request> </mx:operation> </mx:WebService> <mx:XML id="folderData" /> <mx:Box width="100%" height="100%" horizontalAlign="center" verticalAlign="middle"> <mx:Tree id="facilityTree" dataProvider="{folderData.row}" width="100%" height="100%" labelField="@label" showRoot="false" itemOpening="loadChildFolders(event)" fontFamily="Arial" fontSize="10" change="facilityClick(event)" /> </mx:Box> </mx:Canvas> So the problem is that I want to be able to tell it to open a specific node from within the framework. If I knew how to do this, i could probably take the web service out of this file too... can anyone point me in the right direction?? Thanks so much! Adam