6 Replies Latest reply on Oct 6, 2008 8:59 AM by Newsgroup_User

    Tree from 3 ArrayCollections

    BamaGambler
      I want to build a tree as follows:

      Topic (as branch)
      -> Chapter (as branch)
      ----> Lesson (as leaf)

      I have the follow three variable of ArrayCollection type:

      acTopic with fields topic_id, topic_name
      acChapter with fields chapter_id, topic_id, chapter_name
      acLesson with fields lesson_id, topic_id, chapter_id, lesson_name

      Do you know a good strategy to build my tree placing each Chapter in the appropriate Topic leaf and each Lesson in the appropriate Chapter leaf?

      Thanks!
        • 1. Re: Tree from 3 ArrayCollections
          Ventis85 Level 1
          It's much better to have just one arraycollection with topics in it that have chapters in it that have lessons in it. The tree component does the rest.
          Another benefit of this is that you don't need the foreign keys. A lesson naturally belongs to a certain chapter and a chapter belongs to a certain topic.

          I would change the way you receive your data but if you can't run some for each loops to get it all in one arraycollection.
          • 2. Re: Tree from 3 ArrayCollections
            BamaGambler Level 1
            The data is coming from a mySQL database. There are 3 different tables. I'm using the php generated by Flex 3 which uses a function to create XML formatted data. I'm not sure how I would alter the code to return the XML in a way that I could read it in directly to one ArrayCollection.

            How can I loop through my 3 ArrayCollection variable to create a single ArrayCollection?
            • 3. Tree from 3 ArrayCollections
              BamaGambler Level 1
              (duplicate post removed)
              • 4. Re: Tree from 3 ArrayCollections
                Level 7

                "BamaGambler" <webforumsuser@macromedia.com> wrote in message
                news:gccuan$noq$1@forums.macromedia.com...
                > The data is coming from a mySQL database. There are 3 different tables.
                > I'm
                > using the php generated by Flex 3 which uses a function to create XML
                > formatted
                > data. I'm not sure how I would alter the code to return the XML in a way
                > that
                > I could read it in directly to one ArrayCollection.

                This is where it helps to understand the technologies involved rather than
                having a wizard write the code for you. You could use AMFPHP to have it
                return the objects to you already formatted, or you could use Joins to
                return your data in one big dump. Not sure if mySQL supports SHAPE queries,
                which are really good for this kind of structure.

                HTH;

                Amy


                • 5. Re: Tree from 3 ArrayCollections
                  BamaGambler Level 1
                  I agree. I'm trying to learn here I promise. I'm using lynda.com and he uses the PHP code generated by Flex 3. I actually went in there and changed some stuff (e.g. the sql), but I don't know to generate the XML data by myself without using the XML serializer. Is it as simple as using PHP to echo the tags? Do I need some kind of special header returner?
                  • 6. Re: Tree from 3 ArrayCollections
                    Level 7

                    "BamaGambler" <webforumsuser@macromedia.com> wrote in message
                    news:gcdbem$b0p$1@forums.macromedia.com...
                    >I agree. I'm trying to learn here I promise. I'm using lynda.com and he
                    >uses
                    > the PHP code generated by Flex 3. I actually went in there and changed
                    > some
                    > stuff (e.g. the sql), but I don't know to generate the XML data by myself
                    > without using the XML serializer. Is it as simple as using PHP to echo
                    > the
                    > tags? Do I need some kind of special header returner?

                    You can probably find something out there that will take a recordset and
                    output it as XML. The problem with that is it will probably output the
                    exact RS structure, and what you need to do is to check at each loop for a
                    change in your parent object's primary key. If that is different than the
                    previous record, you need to start a new parent. And so on, for each level.

                    Another option is to just take that big flat XML that you get from whatever
                    utility you find by googling and use it as a source for a
                    GroupingCollection. I have an example of how to group flat data at
                    http://flexdiary.blogspot.com.

                    Sorry I can't make this any more painless for you, but you're going to find
                    as you learn Flex that you'll run into lots of tasks that you'll need to
                    learn a lot before you can make something custom happen.