I've done the same thing as you said, if you look at the code once again you can clearly note that treeDetails is an Object and not an array, yet can't find the solution for it. For your referance please see the mxml file below.
 
Regards,
Arun

 
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
 xmlns:mx="
http://www.macromedia.com/2003/mxml"
  width="100%"
 height="100%"
 marginBottom="0"
 marginLeft="0"
 marginRight="0"
 marginTop="0"
 verticalGap="0"
 horizontalGap="0">
 <mx:RemoteObject
  id="RO"
  result="treeDetails.children=event.result"
  fault="mx.controls.Alert.show((event.fault.faultstring, 'Error'))"
  source="Tree.BuildTree"
  showBusyCursor="true" >
   <mx:method name="getTreeData" />
 </mx:RemoteObject>
 <mx:Panel
  creationComplete="RO.getTreeData();" width="258" height="471">
  
  <mx:Script>
  <![CDATA[
   var treeDetails  : Object = [{name: "Base"}];
   var srcNode   : Object;
   var srcParentNode  : Object;
   
   public function onClickOfUpdate()
   {
    //var arr:Array = mx.utils.ArrayUtil.toArray(treeComponent.dataProvider);
    var arr:Array = treeComponent.dataProvider.getProperty("children");
    RO.updateTreeData(arr);
   }
   
   public function treeClick(event)
   {
    srcParentNode = treeComponent.selectedNode.getParent();
   }
   
   function onClickOfUp()
   {
    if(srcParentNode.indexOf(treeComponent.selectedNode) > 0)
    {
     var srcNode = treeComponent.selectedNode;
     var index = srcParentNode.indexOf(srcNode);
     srcParentNode.removeTreeNodeAt(srcParentNode.indexOf(treeComponent.selectedNode));
     srcParentNode.addTreeNodeAt(index-1, srcNode);
    }
    else if(srcParentNode.getProperty('name') == undefined ||
      srcParentNode.indexOf(treeComponent.selectedNode) == undefined) // when no node is selected
    {
     mx.controls.Alert.show("Please select a node before moving or The selected node is the Root node");
    }
    else // Selected node is the first node of its parent
    {
     mx.controls.Alert.show("Can't Move further Up");
    }
   }
 
   function onClickOfDown()
   {
    /* if the selected node last node of it's parent, move the node a position below */
    if(srcParentNode.indexOf(treeComponent.selectedNode)< srcParentNode.getChildNodes().length-1)
    {
     var srcNode = treeComponent.selectedNode;
     var index = srcParentNode.indexOf(srcNode);
     srcParentNode.removeTreeNodeAt(index);
     srcParentNode.addTreeNodeAt(index + 1,srcNode);
    }
    else if(srcParentNode.getProperty('name') == undefined ||
      srcParentNode.indexOf(treeComponent.selectedNode) == undefined) // when no node is selected
    {
     mx.controls.Alert.show("Please select a node before moving or The selected node is the Root node");
    }
    else // Selected node is the last node of its parent
    {
     mx.controls.Alert.show("Can't move further down");
    }
   }
   
  ]]>
  </mx:Script>
  
  <mx:HBox horizontalAlign="center" verticalAlign="middle" width="99%" height="40">
   <mx:Button label="Up" click="onClickOfUp();" />
   <mx:Button label="Down" click="onClickOfDown();" />
   <mx:Button label="Update" click="onClickOfUpdate();" />
  </mx:HBox>
 
  <mx:Tree id = "treeComponent"
   dataProvider="{treeDetails.children}"
   labelField="name"
   cellPress="treeClick(event);"
   width="100%"
   height="86%"
   marginBottom="0"
   marginLeft="0"
   marginRight="0"
   marginTop="0"
   verticalGap="0"
   horizontalGap="0"
   borderThickness="0"
   backgroundSize="0"
   borderSides="0"
   hScrollPolicy="auto"
   vScrollPolicy="auto"
   fontFamily="Arial"
   fontSize="12"
   fontWeight="bold"/>
 </mx:Panel>
</mx:Application>
<!-- End of TreeCmp -->

 

Matt Chotin <[EMAIL PROTECTED]> wrote:

You need to make sure that the dataProvider you assign to the Tree is single Object, not an array.  So where you have treeDetails that should not be an Array but perhaps just the object.  I would then also wait to assign the Tree.dataProvider until the result has come back.  That way you can set up the whole structure, assign the dataProvider, and the nodes should be constructed correctly. 

 

Good luck!

 

Matt


From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of Arunkumar S
Sent: Monday, November 07, 2005 11:52 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Re: Problem with type casting a TreedataProvider back to array...

 

I've attached the files again, please find a solution or work around for me...

 

Regards,

Arun

m_chotin <[EMAIL PROTECTED]> wrote:

can you re-post the file please?  macromedia started bouncing
flexcoders mails today but i think we're back.

--- In flexcoders@yahoogroups.com, Arunkumar S <[EMAIL PROTECTED]> wrote:
>
> Thanks for your reply Matt...

> Your code looks to solve the typecasting problem. But the tree is
not visible as i said in the earlier mail. I have worked with all the
API i know, yet i'm not reacing the solution... I have attached the
full sample you have asked for, can your please try this code and tell
where it went wrong...??

> My ultimate aim is to get the updated ArrayList after making changes
in the tree.

> It would be helpful for me when you make the tree visible when

> dataProvider = {treeDetails}

> or can anyone help me in getting a solution to get the updated
ArrayList.

> Awaiting for your reply. Thanks in advance.

> Regards,
> Arun.

> Note : While running the application use Up & Down buttons to move
the nodes and Update button to reflect changes.

>
> Matt Chotin <[EMAIL PROTECTED]> wrote: v\:*
{behavior:url(#default#VML);}o\:* {behavior:url(#default#VML);}w\:*
{behavior:url(#default#VML);}.shape {behavior:url(#default#VML);}
> Give us a full small example to work with.  You should really just
play around with the TreeDataProvider API and use a debugger to see if
you can figure out where things are going wrong, that's all I'm going
to do too if I have time.
>

>
> ---------------------------------
>
>
> From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com]
On Behalf Of Arunkumar S
> Sent: Friday, October 28, 2005 5:24 AM
> To: flexcoders@yahoogroups.com
> Subject: RE: [flexcoders] Problem with type casting a
TreedataProvider back to array...
>
>

>
> Thanks for your reply Matt...
>
>

>
>
> I tried your code, initially the tree doesn't appears and when i change
>
>

>
>
> dataProvider = {treeDetails.children}
>
>

>
>
> the tree is loaded without any problem, but i when i assign
>
>

>
> var arr:Array = treeCmp.dataProvider.getProperty("children");
>

>
> the arr is shown as undefined, this is because the dataProvider is
already a children of treeDetails. Can you find some other way to
solve the problem...??
>

>
> Reagrds,
>
> Arun.
>
>
>
> Matt Chotin <[EMAIL PROTECTED]> wrote:
>
>
> A TreeDataProvider cannot be an array.  It has to be a single object
that has a child array.  So try creating an object like this:
>

>
> Var treeDetails:Object = {label: `root'};
>
> treeDetails.children = treeList;
>

>
> get the array of details back:
>

>
> var arr:Array = treeCmp.dataProvider.getProperty("children");
>

>
> Matt
>

>
> ---------------------------------
>
>
> From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com]
On Behalf Of Arunkumar S
> Sent: Thursday, October 27, 2005 4:45 AM
> To: flexcoders@yahoogroups.com
> Subject: [flexcoders] Problem with type casting a TreedataProvider
back to array...
>
>

>
> Hi all,
>
>

>
>
> I am assigning an array as TreedataProvider.
>
>

>
>
> When i'm moving the position of nodes of the tree (using
addTreeNodeAt  /  removeTreeNodeAt), the dataProvider is not updated
to the changed nodes, so i'm explicitly typecasting and assignig back
to array.
>
>

>
>
> This seems to behave abnormally (undefined node added to the tree at
the top)...
>
>

>
>
> Here are some pieces of code i use....
>
>

>
>

>
>
> var treeDetails  : Array; // This is assigned as the dataProvider
for the tree
>
>
> :
>
>
> :
>
>
> treeDetails = treeList; // treeList is a array got from Java which
has HashMaps at each row
>
>
> :
>
>
> :
>
>
> // After moving nodes treeDetails is
>
>
> treeDetails = mx.utils.ArrayUtils.toArray(treeCmp.dataProvider) ;
//treeCmp is tree's ID
>
>

>
>

>
>
> Then i'm passing back treeDetails to Java, i'm getting "Error: An
error occurred during service invocation". While assigning
dataProvider to treeDetails i can notice that a undefined node added
to the top.
>
>

>
>
> Also i noticed that when using a simply array in flex every thing is
working fine, and when the array contains object dataProvider is not
updated and also i'm getting error in java when typecasting and send
it as array.
>
>

>
>
> Can anyone give me an idea what could have caused the problem.
Please give me a solution.
>
>

>
>
> Thanks in advance.
>
>

>
>
> Regards,
>
>
> Arun.
>
>
>
> ---------------------------------
>
>
> Yahoo! FareChase - Search multiple travel sites in one click.
>
>
> ---------------------------------
>
>
> Yahoo! FareChase - Search multiple travel sites in one click.
>
>
> --
> Flexcoders Mailing List
> FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.com
>
>
>
>
> ---------------------------------
> YAHOO! GROUPS LINKS
>
>
>     Visit your group "flexcoders" on the web.
>  
>     To unsubscribe from this group, send an email to:
>  [EMAIL PROTECTED]
>  
>     Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service.
>
>
> ---------------------------------
>
>
>
>
>
>
>            
> ---------------------------------
>  Yahoo! FareChase - Search multiple travel sites in one click.
>




Yahoo! FareChase - Search multiple travel sites in one click.


Yahoo! FareChase - Search multiple travel sites in one click.

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




YAHOO! GROUPS LINKS




Reply via email to