6 Replies Latest reply on Sep 6, 2011 10:49 AM by Kristin95762

    loading a dataProvider from a class file

    Kristin95762 Level 1

      Hello

       

      This code is in the class file. I want to replace the code that's commented out with the code below it. I just don't know how to get access to the publishedWorksList. Getting an error: Access of undefined property publishedWorksList. I have bindings on the other variables that work fine.

       

      /*private function loadPublishedWorksResult(event:SQLEvent):void

      {

           var data:Array = selectPublishedTitles.getResult().data;

           adwTitlesDP = new ArrayCollection(data);

      }*/

       

       

       

      private function loadPublishedWorksResult(event:SQLEvent):void

      {

       

           var result:SQLResult = selectPublishedTitles.getResult();

           var numResults:int = result.data.length;

       

       

           for (var i:int = 0; i < numResults; i++)

           {

                var row:Object = result.data[i];

                var bookTitle:String = row.title;

                adwWebsite = row.website;

                adwAuthorComments = row.comments;

       

       

                publishedWorksList.dataProvider.addItem({label:bookTitle});

           }

       

      }

       

      Thanks

       

      Kristin

        • 1. Re: loading a dataProvider from a class file
          kokorito Level 4

          easiest way would be have a class variable arraycollection which  loadPublishedWorksResult adds to

          then have  publishedWorksList bind to it as the dataprovider

          • 2. Re: loading a dataProvider from a class file
            Kristin95762 Level 1

            Whoa! English....

             

            But let me take a stab at what you mean.

             

            Are you saying something like: (I'm modifying an example I found in the FB4/Flex 4 Bible, pg 545 in case you have the book. Don't understand it though)

             

            package valueObjects

            {

                 [Bindable]

                 public class AuthorDetails

                 {

                      public var title:String;

                      public var website:String;

                      public var comments:String;

             

                      public function AuthorDetails()

                      {

                      }

                 }

            }

             

            Should I then run my sqlstatements here?

             

            I'm not seeing it.

             

            Thanks again.

             

            Kristin

            • 3. Re: loading a dataProvider from a class file
              kokorito Level 4

              at the moment your loadPublishedWorksResult is trying to add an item to the dataprovider of publishedWorksList which isnt in the same scope

               

              so instead make a class variable, in the class

               

              [Bindable] public var worksList:ArrayCollection;

               

              in the loadPublishedWorksResult method instantiate the arraycollection and add items to it

               

               

               

              then in the main, bind the publishedWorksList to it

               

              <s:List id="publishedWorksList" dataProvider="{myClass.worksList}"/>

              • 4. Re: loading a dataProvider from a class file
                Kristin95762 Level 1

                Okay, currently this is in my class file, just after the package declaration:

                 

                [Bindable]

                public var adwTitlesDP:ArrayCollection;

                 

                and this is in the application file:

                 

                <s:List id="publishedWorksList"

                     x="385" y="196" width="285"

                     dataProvider="{authorDetails.adwTitlesDP}"               (in the constructor function:  authorDetails = new AuthorDetailsClass();)

                     labelField="title"/>

                 

                So far, this looks like what you have posted.

                 

                The function in question: The list box may contain many book titles, while the other controls only represent one cell in the table. That's my hope at least.

                 

                private function loadPublishedWorksResult(event:SQLEvent):void

                {

                     var result:SQLResult = selectPublishedTitles.getResult();

                     var numResults:int = result.data.length;

                 

                 

                     for (var i:int = 0; i < numResults; i++)

                     {

                          var row:Object = result.data[i];

                          var bookTitle:String = row.title;

                          adwWebsite = row.website;

                          adwAuthorComments = row.comments;

                 

                 

                          publishedWorksList.dataProvider.addItem({label:bookTitle});               (problem line)

                     }

                }

                 

                So I instantiate the arrayCollection thusly (?):

                 

                myTitlesAC = new adwTitlesDP;

                 

                Then I have to change the reference to the dataProvider of my list I suppose.

                 

                Assigning data to myTitlesAC....

                 

                myTitlesAC = what???

                 

                Thanks for your help.

                 

                KRistin

                • 5. Re: loading a dataProvider from a class file
                  kokorito Level 4

                  you cant add items directly to the list dataprovider because it is outside the class (problem line)

                  but you have bound the list to a variable inside the class, so use that

                   

                   

                   

                   

                  private function loadPublishedWorksResult(event:SQLEvent):void

                   

                  {

                   

                  var result:SQLResult = selectPublishedTitles.getResult();

                   

                  var numResults:int = result.data.length;

                   

                   

                  adwTitlesDP = new ArrayCollection();

                   

                   

                  for (var i:int = 0; i < numResults; i++)

                   

                  {

                   

                  var row:Object = result.data[i];

                   

                  var bookTitle:String = row.title;

                   

                  adwWebsite = row.website;

                   

                  adwAuthorComments = row.comments;

                   

                   

                   

                   

                   

                  adwTitlesDP.addItem({label:bookTitle});

                   

                  }

                   

                  }

                  • 6. Re: loading a dataProvider from a class file
                    Kristin95762 Level 1

                    Hi

                     

                    Darn, I almost had that on my own. Just didn't realize where the dataprovider was instantiated. Thanks a lot.

                     

                    Really appreciate the help.

                     

                    Kristin