13 Replies Latest reply on Mar 18, 2011 8:53 AM by Zlaper

    Using a Vector as a DataProvider ?

    Zlaper

      When I try to assign a Vector as a dataprovider, I get the compile time error:

       

      Description    Resource    Path    Location    Type
      1067: Implicit coercion of a value of type __AS3__.vec:Vector.<Object> to an unrelated type mx.collections:IList.    GeneralTest.mxml    /GeneralTest/src    line 12    Flex Problem

       

      My work around is to parse the vector and create an ArrayCollection by adding each individual element to the collection.

       

      Is there a better way ?

        • 1. Re: Using a Vector as a DataProvider ?
          pauland Level 4

          ..perhaps don't use Vector in the first place?

           

          Rather depends on what you are doing.

          • 2. Re: Using a Vector as a DataProvider ?
            Zlaper Level 1

            Hello, thanks for the prompt answer.

             

            I'm using Vectors for performance and type safety. Mostly for the latter.

            I don't think that "don't use them" is an acceptable answer, since the functionality is supported in Flex 4.

             

            My query concerns mostly how to efficiently use them as dataproviders.

             

            Thanks.

            • 3. Re: Using a Vector as a DataProvider ?
              David_F57 Level 5

              Hi,

               

              I think looking at ilist sort of sums it up, then again I may be reading the doco incorrectly,

               

              "There are several IList implementations included in the Flex framework, including ArrayCollection, ArrayList, and XMLListCollection."

               

              http://help.adobe.com/en_US/Flex/4.0/UsingSDK/WS2db454920e96a9e51e63e3d11c0bf69084-7b6b.ht ml - all about dataproviders

               

              to me it means vector is not directly usable as a dataprovider, not that you couldn't create a class that does the conversion.

               

              David.

              • 4. Re: Using a Vector as a DataProvider ?
                Zlaper Level 1

                Hello David,

                 

                Thanks for your reply. That is actually what I'm currently doing (using a wrapper class).

                 

                I'm just wondering if there is a "best-practice" or "optimal way" to handle vectors as dataproviders.

                 

                Thanks.

                • 5. Re: Using a Vector as a DataProvider ?
                  David_F57 Level 5

                  hi,

                   

                  when vectors first became available for flash there was a lot info popping up things like away3d use them to improve performance asmod3d makes heavy use of vectors in graphic manipulation routines.

                   

                  It seems for array based math vectors are getting a lot of attention, very little information is out there about vectors for pure data arrays. Not sure that this is due to the overhead involved in 'reformating'  vectors to be compliant with existing data structures or that there is just no real advantage.

                   

                  As for best practice, after academics, second hand car salesmen, janitors and Steve Jobs started setting the standard I figured it was time to just do what you feel comfortable with and you know works and is maintainable.

                   

                  David.

                  • 6. Re: Using a Vector as a DataProvider ?
                    pauland Level 4

                    Zlaper wrote:

                     

                    Hello, thanks for the prompt answer.

                     

                    I'm using Vectors for performance and type safety. Mostly for the latter.

                    I don't think that "don't use them" is an acceptable answer, since the functionality is supported in Flex 4.

                     

                    My query concerns mostly how to efficiently use them as dataproviders.

                     

                    Thanks.

                     

                    Well, "Don't use them" is perfectly valid advice if you are not doing much besides setting up data for use as a Dataprovider. If you are doing minimal processing using Vectors, then any performance gain may be dwarfed by the conversion process and make your code more complicated than neccessary. On the other hand, if you use them a lot as vectors, then conversion might be sensible.

                     

                    We can only guess whether converting from a Vector is a suitable route, or just going straight to an Array Collection.

                     

                    The short answer is that you can't use them as a dataProvider and there is no magic shortcut to conversion, though as others have suggested you could make your own Vector based class that could act as a DataProvider, though I doubt it woukd be worth the hassle.

                     

                    Because Flex4 offers functionality, doesn't mean it's the best approach for a particular scenario.

                    • 7. Re: Using a Vector as a DataProvider ?
                      David_F57 Level 5

                      Hi,

                       

                      I think Paul and I are pretty much on a similar page here. I haven't really got into vectors that much but they seem to be suited for purposes other than data management.

                       

                      At the end of the day as a coder there are a few things you need to consider

                       

                      1- Am I getting to clever  for my own good

                      2- If I come back to the code in 12 months will it make sense or will my first response be WTF...

                      3- If someone else needs to look at my code tomorrow will their first response be WTF......

                      4- Is the solution maintainable.

                       

                      The rest is what allows us to be creative and proud of what we do.

                       

                      If you can show a vector based data management system is justified and can do it well, all I can say is go for it, who am I to say your solution is better or worse than anyone elses if it works.

                       

                      David

                      • 8. Re: Using a Vector as a DataProvider ?
                        Flex harUI Adobe Employee

                        There are some things missing from AS3's vector implementation that make

                        using Vector in dataproviders quite difficult.  We are asking the VM team to

                        fix those issues so we can have Vector-based DPs in future releases.

                        • 9. Re: Using a Vector as a DataProvider ?
                          David_F57 Level 5

                          Hi Alex,

                           

                          That sounds good, will be interesting to see how that shapes up, a point release maybe ?

                           

                          on another note - not topic related, I have been beating my head against a brick wall (damned new help system) I know there is a call somewhere in the bowels of layouts or scrollers or datagroups to get the first and last items in a view, any ideas ?. or were the replaced with getitemindices ?

                           

                           

                          David

                          • 10. Re: Using a Vector as a DataProvider ?
                            Flex harUI Adobe Employee

                            I see a getItemIndicesInView on DataGroup.

                            • 11. Re: Using a Vector as a DataProvider ?
                              Shongrunden Adobe Employee

                              Hi David,

                               

                              VerticalLayout and HorizontalLayout are the only spark layouts that provide firstIndexInView/lastIndexInView properties.  If you want something similar with other layouts then as Alex pointed out DataGroup.getItemIndicesInView() should do the trick.  Although I guess if you are using a Group that won't help you.  If you would like to see those properties on other layouts please file an enhancement request and post a link here.

                               

                              Thanks,

                              Steve

                              • 12. Re: Using a Vector as a DataProvider ?
                                eprevot123 Level 2

                                Near a year later, is there now a simple way to use Vector as dataprovider ?

                                if no, do you know when we can expect to be able to do it ?

                                • 13. Re: Using a Vector as a DataProvider ?
                                  Zlaper Level 1

                                  Hey! I don't know about an official implementation but I ended up using

                                  this:

                                   

                                  http://www.digitalprimates.net/codeslinger/2010/05/18/vectorcollection/