Which line is throwing the error?
Tracy Spratt, Lariat Services, development services available _____ From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf Of timgerr Sent: Wednesday, May 13, 2009 10:12 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Getting an error when using a tree as a component OK, Here is some code, this is my tree Component: [START] <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe. <http://www.adobe.com/2006/mxml> com/2006/mxml" layout="absolute" creationComplete="Init();"> <mx:Script> <![CDATA[ import mx.events.TreeEvent; import mx.events.IndexChangedEvent; import mx.rpc.events.FaultEvent; import mx.rpc.events.ResultEvent; import mx.rpc.remoting.RemoteObject; import mx.controls.Alert; import mx.collections.ArrayCollection; [Bindable] public var SmallTree_uid:String; [Bindable] public var SmallTree_sessionid:String; [Bindable] private var _acFirst:ArrayCollection; [Bindable] private var _treeDataPrivider:ArrayCollection; /* ----------------------------- [ Remote Calls ] ----------------------------- */ private function RemoteCallFirstRequest():void { var nOb:Object = new Object(); nOb.uid = this.SmallTree_uid; nOb.sessionid = this.SmallTree_sessionid; nOb.call = "BuildTreeStructure" var rmt:RemoteObject; rmt = new RemoteObject( "GenericDestination" ); rmt.source = "com.ArrayTree.Tree"; rmt.MasterCall.addEventListener( FaultEvent.FAULT, this.ServiceError ); rmt.MasterCall.addEventListener( ResultEvent.RESULT, this.ReturnFirstRequestData); rmt.MasterCall(nOb); } /* ----------------------------- [ Remote Returns ] ----------------------------- */ private function ServiceError(f:FaultEvent):void { Alert.show(f.message + " " + f.fault); } private function ReturnFirstRequestData(r:ResultEvent):void { this._acFirst = new ArrayCollection(r.result as Array); this.findRoot(); } /* ----------------------------- [ Event Calls ] ----------------------------- */ private function findRoot():void { this._treeDataPrivider = new ArrayCollection(); for(var i:int = 0; i < this._acFirst.length; i++){ if (this._acFirst[i].PARid == 0 && this._acFirst[i].name != "pseudo_root"){ this._treeDataPrivider.addItem(this._acFirst[i]); } } this.BuildRestOfTree(this._treeDataPrivider); } private function BuildRestOfTree(obj:Object):void { //if(obj.length > 1){ for(var i:int = 0; i < obj.length; i++){ trace(obj[i].CBSid + " " + obj[i].name); var childAry:Array = this.FindChild(obj[i].CBSid); if(childAry.length > 0){ Object(obj[i]).children = childAry; // recures the newly added child trace("he he ha ha " + obj[i].children.length); this.BuildRestOfTree(obj[i].children); } } //} } private function FindChild(numCBSid:String):Array { var ary:Array = new Array(); for(var i:int = 0; i < this._acFirst.length; i++){ if(this._acFirst[i].PARid == numCBSid){ ary.push(this._acFirst[i]); } } return ary; } /** * GetTreeLabel * @param None * @return None * This will get the name of the tree node from the individual object within the * array collection */ public function GetTreeLable(obj:Object):String { return obj.name; } /* ----------------------------- [ init Call ] ----------------------------- */ /** * Init * This is the first call when the page loads * @paran * @return */ public function Init():void { this.SmallTree_sessionid = '123456'; this.SmallTree_uid = '321'; this.RemoteCallFirstRequest(); } ]]> </mx:Script> <mx:Tree x="458" y="243" width="419" dataProvider="{this._treeDataPrivider}" labelFunction="GetTreeLable"></mx:Tree> </mx:Application> [/START] Here is my code calling the tree component: [START] <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe. <http://www.adobe.com/2006/mxml> com/2006/mxml" layout="absolute" creationComplete="Init();"> <mx:Script> <![CDATA[ import com.TreeSmallv3; [Bindable] public var t:TreeSmallv3; public function Init():void { t = new TreeSmallv3(); addChild(t); } ]]> </mx:Script> </mx:Application> [/START]