The dataProvider of your arrayCollection is an array. This array
contains objects which contain an array of objects.

I do the same sort of thing for my menus - Each menu is an object that
can contain submenus (ie. arrays of menuItem objects). Note: This is all
WebOrb.

So, in PHP:
class Menu
{
     public $ID;
     public $label;
     public $ParentMenuID;
     public $children;

     function __construct()
     {
         $this->label = "";
         $this->ParentMenuID = null;
         $this->children = array();
     }
}

class MenuItem
{
     public $ID;
     public $label;
     public $Link;
     public $ParentMenuID;

     function __construct()
     {
         $this->label = "";
         $this->Link = "";
         $this->ParentMenuID = null;
     }
}

Flex:
package myServices
{
     [RemoteClass(alias="Classes.Menu")]
     [Bindable]
     public class Menu
     {
         //instance variables
         private var _ID:String;
         private var _label:String;
         private var _ParentMenuID:int;
         private var _children:Array = new Array();

         //accessor methods
         public function get ID():String {return _ID;}
         public function get label():String {return _label;}
         public function get ParentMenuID():int {return _ParentMenuID;}
         public function get children():Array {return _children;}

         //mutator methods
         public function set ID(ID:String):void {_ID = ID;}
         public function set label(label:String):void {_label = label;}
         public function set ParentMenuID(ParentMenuID:int):void
{_ParentMenuID = ParentMenuID;}
         public function set children(children:Array):void {_children =
children;}
     } // end class Menu
}//end package

package myServices
{
     [RemoteClass(alias="Classes.MenuItem")]
     [Bindable]
     public class MenuItem
     {
         //instance variables
         private var _ID:String;
         private var _label:String;
         private var _Link:String;
         private var _ParentMenuID:int;

         //accessor methods
         public function get ID():String {return _ID;}
         public function get label():String {return _label;}
         public function get Link():String {return _Link;}
         public function get ParentMenuID():int {return _ParentMenuID;}

         //mutator methods
         public function set ID(ID:String):void {_ID = ID;}
         public function set label(label:String):void {_label = label;}
         public function set Link(Link:String):void {_Link = Link;}
         public function set ParentMenuID(ParentMenuID:int):void
{_ParentMenuID = ParentMenuID;}
     } // end class Menu
}//end package


I parse the records from a MySQL database and create arrays as required.
I then populate the children property with the array of menuItem objects
of the submenu.

When I get the result in Flex I convert it to an ArrayCollection:

menuBarCollection = new
ArrayCollection(ArrayUtil.toArray(event.result));

and then use the data in my menuBar:

<mx:MenuBar id="menuBar" dataProvider="{menuBarCollection}"/>

HTH


Steve


--- In [email protected], "timgerr" <[EMAIL PROTECTED]> wrote:
>
> So I am trying to build a MPTT (nested tree) object in php, I have a
> few questions for this group because I am not sure how the data should
> be returned.  I have been using static data and have a few questions
> on what is contained within the data.  Here is my arraycollection:
> private var myDataProvider:ArrayCollection = new ArrayCollection([
>   Region:"Southwest",ID:"1",Territory_Rep:"Tom Jones", children: [
>     {Region:"Arizona",ID:"2", children: [
>  {Territory_Rep:"Barbara Jennings", ID:"3"},
>  {Territory_Rep:"Dana Binn",ID:"4"}]},
>     {Region:"Central California",ID:"5", children: [
>         {Territory_Rep:"Joe Smith", ID:"6"}]},
>  {Region:"Nevada", ID:"7", children: [
>     {Territory_Rep:"Bethany Pittman",ID:"8"}]},
>  {Region:"Northern California", ID:"9", children: [
>     {Territory_Rep:"Lauren Ipsum",ID:"10"},
>     {Territory_Rep:"T.R. Smith",ID:"11"}]},
>  {Region:"Southern California",ID:'12', children: [
>     {Territory_Rep:"Alice Treu", ID:'13'},
>     {Territory_Rep:"Jane Grove",ID:"14"}]}
>    ]}
> ]);
>
> I am in need of some guidance, so bear with me :). I think that this
> is an object {Territory_Rep:"Joe Smith", ID:"6"}, is this an array
> with an object {Region:"Central California",ID:"5", children: [
>         {Territory_Rep:"Joe Smith", ID:"6"}]} ?
>
> Here is my problem, I am creating some php data returns to flex with
> arrays, object, assoc arrays.  I am not sure what a flex
> arraycollection is so I am running some tests.  Here are some tests
> that I have done,
> Example #1
> PHP CODE
> $o1->name = 'Tom';
> $o1->status = 'Dad';
>
> $o2->name = 'Wendy';
> $o2->status = 'Daughter';
> $b[] = $o2;
> $o1->child = $b;
> $arr[] = $o1;
> return $arr;
>
> Charles Proxy Sees This:
> com.mptt.MPTT.GetTree
> Parameters
> Results
>  [0]
>   name
>   status
> child
>  [0]
>   name
>   status
>
> Example #2
> $o1->name = 'Tom';
> $o1->status = 'Dad';
>
> $o2->name = 'Wendy';
> $o2->status = 'Daughter';
> $o1->child = $o2;
> $arr[] = $o1;
> return $arr;
>
>
> com.mptt.MPTT.GetTree
> Parameters
> Results
>  [0]
>   name
>   status
>   child
>    name
>    status
>
>
> Example #3
> $o1->name = 'Tom';
> $o1->status = 'Dad';
>
> $o2->name = 'Wendy';
> $o2->status = 'Daughter';
> $o1->child = $o2;
> return $o1;
>
> com.mptt.MPTT.GetTree
> Parameters
> Results
>  name
>  status
>  child
>   name
>   status
>
> So when I return the 3 examples int an arraycollection:
> var ac:ArrayCollection = new ArrayCollection(result.result as Array);
> and use that array collection as a dataprovider for a combobox
>
> <mx:ComboBox x="204" y="107" id="cmbox" dataProvider="{ac}"
> labelField="name"></mx:ComboBox>
>
> Only example 1 and 2 return anything and that is only the first name,
> none of the child names propagate the Combobox.
>
> So my question with all of this, how (what format) should I return my
> data from php to flex so I can add it (the data) to an
arraycollection.
>
> Thanks for all the help, this group rocks,
> timgerr
>
> --- In [email protected], "timgerr" tgallagher@ wrote:
> >
> > Hello all,
> > I am working with nested arrayobjects and I cannot construct the
> > needed data from my php/mysql backend.
> >
> > I am using nested sets
> >
(http://dev.mysql.com/tech-resources/articles/hierarchical-data.html),
> > with left and right keys.  I need to construct the data (in php) and
> > pass it to flex (using a remote call). I need/want to get the data
to
> > flex and put it into an arraycollection.  Has any one done this?  If
> > so, can you post some code?  I have been banging my head on this for
a
> > long time and cannot get the data into the right format for an array
> > collection.
> >
> > Thanks for the help,
> > timgerr
> >
>

Reply via email to