12 Replies Latest reply on Nov 2, 2006 2:43 PM by yojimbo

    ArrayCollection as result


      Hi, trying to use ArrayCollection as result container but cant get it to populate a DataGrid

      this is based on example on page 1153/4 of flex2_devguide.pdf

      .. usual stuff

      <mx:HTTPService id="gameRequest" url="data/gameList.xml" showBusyCursor="true"/>
      <mx:ArrayCollection id="gameArray" source="gameRequest.lastResult.FMPDSORESULT.ROW"/>
      <mx:Button label="getGames" click="gameRequest.send()" x="722" y="14"/>
      <mx:DataGrid x="10" y="104" width="796" height="380" id="gameList" dataProvider="{gameArray}" >

      - with ArrayUtil conversion also, as in example

      <mx:ArrayCollection id="gameArray" source="{ArrayUtil.toArray(gameRequest.lastResult.FMPDSORESULT.ROW)}"/>

      In both case all I is see is the DataGrid filled with the source value as a string ie "{ArrayUtil.toArray(gameRequest.lastResult.FMPDSORESULT.ROW)}" then no update after the send?

      Data is ok because ignoring the ArrayCollection thus, loads the data fine:

      <mx:DataGrid x="10" y="104" width="796" height="380" id="gameList" dataProvider="{gameRequest.lastResult.FMPDSORESULT.ROW}" >

      tried other similar examples for instance page 1142/3, copied direct with only changes to load my data, with ArrayCollection nothing, with dataProvider no problem

      FYI Mac Flex 2

      thanks for any help.
        • 1. Re: ArrayCollection as result
          leotemp Level 1
          Is there any particular reason you are using an array collection? You may need to do this:

          <mx:DataGrid x="10" y="104" width="796" height="380" id="gameList" dataProvider="{gameArray[0]}" >

          • 2. Re: ArrayCollection as result
            yojimbo Level 1
            Hi, cheers for the reply

            but still broken, dataBinding is not compatible with that syntax, but even with the correct ( gameArray.getItemAt(0)) == same prob

            Reason i want to use the ArrayCollection is i will be adding filtering and searching to the data, and you need to use the ArrayCollection for that.

            • 3. Re: ArrayCollection as result
              leotemp Level 1
              Please post the structure of your returned xml
              • 4. Re: ArrayCollection as result
                yojimbo Level 1

                ok here it is, this a direct dump from a Filemaker DB so theres some unused data but this shouldnt cause a problem: This will be tidied up as im porting this to SQL as part of this process.


                This will load fine into the DataGrid if I target the dataProvider direct, dataProvider="{gameRequest.lastResult.FMPDSORESULT.ROW}"

                • 5. Re: ArrayCollection as result
                  yojimbo Level 1

                  the plot thickens.

                  I replaced the direct source population on the ArrayCollection and went via a result function for gameRequest:

                  private var gameArray:ArrayCollection;
                  private function receivegameList(event:ResultEvent):void{

                  and it works with the binding, on doing some debugging the i saw that gameRequest.lastResult.FMPDSORESULT.ROW was already an ArrayCollection, so now it points to the source parameter being wrong or buggy because if i use source="{gameRequest.lastResult.FMPDSORESULT.ROW}" on an ArrayCollection component i get a coercion error as if im trying to make the result into an Array. Looks like a bug to me cos this is how the exmaples are done but it dosent want to work.

                  • 6. Re: ArrayCollection as result
                    leotemp Level 1
                    Here you go, i just tested this so i know it works. Try doing your data manipulation in script as its allot easier to tell whats going on:

                    <?xml version="1.0" encoding="utf-8"?>
                    <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">

                    <mx:HTTPService id="gameRequest" url="data/gameList.xml" showBusyCursor="true" result="{parseGames(event)}"/>

                    import mx.rpc.events.ResultEvent;
                    import mx.utils.ArrayUtil;
                    import mx.collections.ArrayCollection;

                    private var gameArray:Array; //Stores assets to load //
                    private function parseGames(event:ResultEvent):void {
                    gameArray= mx.utils.ArrayUtil.toArray(event.result.FMPDSORESULT.ROW);
                    debug.text= "array created!";
                    gameList.dataProvider= gameArray[0];
                    debug.text= "data grid populated!";


                    <mx:Button label="getGames" click="gameRequest.send()" x="10" y="10"/>
                    <mx:DataGrid x="10" y="40" width="796" height="380" id="gameList">
                    <mx:Label x="113" y="14" text="debug" id="debug"/>

                    • 7. Re: ArrayCollection as result
                      yojimbo Level 1

                      right, can i ask what version of FlexBuilder you're running im on OSX flex Builder 2.0.151447

                      cos running this here will give me a coercion error:
                      TypeError: Error #1034: Type Coercion failed: cannot convert mx.collections::ArrayCollection@a9d9d61 to Array.

                      here result is of type ArrayCollection (via the debugger) not Array which is probably why the source binding fails. To prove this if i then try to set the source of an ArrayCollection with the result it also throws a coercion error as source must be an Array.

                      As it seems via the result Function we have an ArrayCollection ill now try using the iCollectionView methods to filter.

                      • 8. Re: ArrayCollection as result
                        leotemp Level 1
                        Im not sure i understand what your saying, "source must be an Array" source of what? I am running the most up to date version of flex and have a good dozen apps out there running the same way as I posted above. Did you try to compile just the posted app or try merging it with what you have? I guess it doesn't matter if working code wont compile in your builder I cant really help you beyond posting what I already have, sorry :(

                        FYI you should be able to do whatever you need with the XMLList without converting it to an array such as the iCollectionView:

                        • 9. Re: ArrayCollection as result
                          yojimbo Level 1
                          hi, update:

                          yes the result is most definitely ArrayCollection, simple filter function works!

                          maybe this something new in the OSX version not in yours or just a bug?
                          • 10. ArrayCollection as result
                            leotemp Level 1
                            I guess your saying that in your flex if you point a collection at an array it wont just stick in the first dimension? Thats weird and I hope they don't change it.

                            Who knows, I stopped even trying to use flex builder on my mac the performance was so terrible and somehow it got stuck insisting a file it was dependent on no longer existed even if the entire project was removed/deleted it would still flag the file as an error and not compile apps in different projects :( So now im in XP Pro on my AMD system and its much more stable only now i have to deal with all the things windows does to me on a daily basis, my favorite: typing "www." in my web browser causes all my cd/dvd drives to spin up and access(a good 10 second delay) cuz you never know when the "www." domain alias might point to a cd rom.. >:0
                            • 11. Re: ArrayCollection as result
                              yojimbo Level 1

                              by source i mean the source parameter for the ArrayCollection Component, you should be able to bind this according to several examples in the dev guide and remove the need for the HTTPService result method.

                              <mx:ArrayCollection id="gameArray"

                              this fails here, either with a coercion error if used with ArrayUtil or without because lastResult is not an Array, i asume as youve done some apps youre on a pc, can you try this method? examples on pages 1153/4 & 1142/3

                              • 12. Re: ArrayCollection as result
                                yojimbo Level 1

                                yup it is a dog, Java is so slow on the mac.

                                well at least i have it working now albeit oddly, ill do a test project and then flag this up as a bug, cheers for your help, so much for quick application development!