1 Reply Latest reply on Oct 27, 2009 2:16 PM by Peter deHaan

    How to combine XMLListCollections

    Handycam Level 1

      I have 5 components.  Each contains an XMLListCollection bound to a list that people can add stuff to (from a different list/XLC).


      The adding is working, since if I trace the component I get results:


      private function testBtn(event:MouseEvent):void {
           for each (var x:XML in step1.itemChosenColl){


      Where step1 is one of the components and itemChosenCollection is the list's DP.


      It traces the ln1 attribute of each item in the collection, as expected.


      Now I'd like a new collection of all the other collections, and pass this to another "final" component.  This component has a public XLC variable bound to a datagrid.  But this fails:


      recipe.completeIngredients = step1.itemChosenColl + step2.itemChosenColl;

      Saying I cannot coerce into an XLC.  So how is this done?

        • 1. Re: How to combine XMLListCollections
          Peter deHaan Level 4

          @Steve Lombardi,


          Try something like this. The XMLListCollection (and presumably other IList implementers) have an addAll() method, where you can specify the two collections to combine:


          <?xml version="1.0" encoding="utf-8"?>
          <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                  <s:Button click="button1_clickHandler(event);" />
                      protected function button1_clickHandler(evt:MouseEvent):void {
                  <s:XMLListCollection id="xmlListColl1">
                      <fx:XMLList xmlns="">
                          <item label="1. One" />
                          <item label="1. Two" />
                          <item label="1. Three" />
                          <item label="1. Four" />
                          <item label="1. Five" />
                  <s:XMLListCollection id="xmlListColl2">
                      <fx:XMLList xmlns="">
                          <item label="2. Six" />
                          <item label="2. Seven" />
                          <item label="2. Eight" />
                          <item label="2. Nine" />
              <s:List id="lst"
                      left="20" top="20" />