12 Replies Latest reply on Dec 30, 2008 9:33 AM by EWN-CMI

    Accordion/Datagrid/Master-Detail Question

    EWN-CMI Level 1
      I have a little simple application I am trying to get going. The layout is an Accordion with 3 Panes, each Pane has a Datagrid populated from MySql based on WHERE clause from the same table (so each row on the Datagrid regardless of Pane has the same structure). I can populate a detail Panel or From with items from a single Pane/Datagrid (ie. dg1.selectedItem.field) with a hardcoded DataSource. What would be the approach to allow the Panel/Form to be populated from any of the Datagrids (dg1, dg2, dg3) without having to duplicate the code 3 times. I am VERY new to OOP but am trying. Thanks in advance for all help and advice.
        • 1. Re: Accordion/Datagrid/Master-Detail Question
          rtalton Level 4
          Using the Accordion's change event, write some code to change which DataGrid is populating the Form based on the Accordion's selectedIndex property.
          • 2. Re: Accordion/Datagrid/Master-Detail Question
            EWN-CMI Level 1
            Thanks for the advice, I am not sure I am using it to solve my original problem, but I am now using a dynamic query using the Accordion selectedIndex to get the WHERE criteria for each DataGrid. Which works great and is much cleaner than my original, Thanks again.

            I also think I figured out how to get the selectedItem from any of the DataGrids without referencing by the id of the DataGrid (i.e. id="ds0") as in itemClick="doTest(ds0.selectedItem.idnumber);" works fine {doTest function currently just calls Alert.show with the passed value and in this format shows the idnumber} my current attempt at referencing the object is also working - itemClick="doTest(event.currentTarget.selectedItem.idnumber)"

            Now I have to try to use the Datagrids selectedItem as the dataProvider for a little custom component (just a couple of standard components on a Canvas)
            Thanks Again.
            • 3. Accordion/Datagrid/Master-Detail Question
              EWN-CMI Level 1

              Thanks Again.
              • 4. Re: Accordion/Datagrid/Master-Detail Question
                ntsiii Level 3
                "...use the Datagrids selectedItem as the dataProvider ..." Binding into a setter function would be a good way to handle this.

                <custom:MyComponent ... aDP="{ds0.selectedItem.aDP}" ... />

                MyComponent :
                ...
                [Bindable]public var _acDP:ArrayCollection;

                public var set aDP(a:Array):void {
                acDP = new ArrayCollection(a);
                }

                <mx:ComboBox dataProvider="{_acDP}"

                Tracy
                • 5. Re: Accordion/Datagrid/Master-Detail Question
                  EWN-CMI Level 1
                  I think I understand and will give it a try. I assume there should not be any issue in changing

                  <custom:MyComponent ... aDP="{ds0.selectedItem.aDP}" ... />

                  to

                  <custom:MyComponent ... aDP="{event.currentTarget.selectedItem..aDP}" ... />

                  I am trying to get away from using the DataGrid id as reference, since each Accordion container has a DataGrid and I want any itemClick event in the Accordion to feed the custom component.

                  Thanks for the help.
                  • 6. Re: Accordion/Datagrid/Master-Detail Question
                    Level 7

                    "EWN-CMI" <webforumsuser@macromedia.com> wrote in message
                    news:gjb8nh$iq0$1@forums.macromedia.com...
                    > Thanks for the advice, I am not sure I am using it to solve my original
                    > problem, but I am now using a dynamic query using the Accordion
                    > selectedIndex
                    > to get the WHERE criteria for each DataGrid. Which works great and is much
                    > cleaner than my original, Thanks again.
                    >
                    > I also think I figured out how to get the selectedItem from any of the
                    > DataGrids without referencing by the id of the DataGrid (i.e. id="ds0")
                    > as in
                    > itemClick="doTest(ds0.selectedItem.idnumber);" works fine {doTest function
                    > currently just calls Alert.show with the passed value and in this format
                    > shows
                    > the idnumber} my current attempt at referencing the object is also
                    > working -
                    > itemClick="doTest(event.currentTarget.selectedItem.idnumber)"
                    >
                    > Now I have to try to use the Datagrids selectedItem as the dataProvider
                    > for a
                    > little custom component (just a couple of standard components on a Canvas)
                    > Thanks Again.

                    You might want to consider just using one dataGrid and passing it back and
                    forth among the accordion children, as seen here:
                    http://flexdiary.blogspot.com/2008/09/groupingcollection-example-featuring.html


                    • 7. Re: Accordion/Datagrid/Master-Detail Question
                      Level 7

                      "EWN-CMI" <webforumsuser@macromedia.com> wrote in message
                      news:gjbasv$lfr$1@forums.macromedia.com...
                      >I think I understand and will give it a try. I assume there should not be
                      >any
                      > issue in changing
                      >
                      > <custom:MyComponent ... aDP="{ds0.selectedItem.aDP}" ... />
                      >
                      > to
                      >
                      > <custom:MyComponent ... aDP="{event.currentTarget.selectedItem..aDP}" ...
                      > />
                      >
                      > I am trying to get away from using the DataGrid id as reference, since
                      > each
                      > Accordion container has a DataGrid and I want any itemClick event in the
                      > Accordion to feed the custom component.

                      You'd use something like:

                      aDP="{currentDataGrid.selectedItem.aDP}"

                      Then just change out which dataGrid you're referring to in currentDataGrid.


                      • 8. Re: Accordion/Datagrid/Master-Detail Question
                        EWN-CMI Level 1
                        Amy, Thanks for the help. I looked at your example and it was a bit over my head - though I would like to know how you get so many "me" days. (lol)

                        I can't try the dataProvider stuff here since I have hit another wall in using FlexDB.swc and will have to figure out why I can't have 2 query results at one time, each time I query with a different EventListener and a different arrayCollection. I will try to find the proper place to pose the question.
                        • 9. Re: Accordion/Datagrid/Master-Detail Question
                          Level 7

                          "EWN-CMI" <webforumsuser@macromedia.com> wrote in message
                          news:gjbipa$1o2$1@forums.macromedia.com...
                          > Amy, Thanks for the help. I looked at your example and it was a bit over
                          > my
                          > head - though I would like to know how you get so many "me" days. (lol)

                          I try to finish projects quickly :-). This time of year is very thin.

                          > I can't try the dataProvider stuff here since I have hit another wall in
                          > using FlexDB.swc and will have to figure out why I can't have 2 query
                          > results
                          > at one time, each time I query with a different EventListener and a
                          > different
                          > arrayCollection. I will try to find the proper place to pose the
                          > question.

                          I'm not sure what's going on with the swc, but I would think that once you
                          get the result and store it into a variable, you can then store a different
                          result in a different variable.


                          • 10. Re: Accordion/Datagrid/Master-Detail Question
                            EWN-CMI Level 1
                            Yes, you would figure that you could reassign it, but either I didn't know how to do it (arrayCollectionvar1 = arrayCollectionvar2). I finally created a second connection and was able to get it to work. Thanks for the help.

                            NOW - a really weird problem (I am so close to having this part done).

                            // Retrieve the image associated with the item selected in the grid
                            private function getImage():void {
                            var cartGrid:DataGrid = dg;
                            var imageSource:String = 'assets/' + cartGrid.selectedItem.statsfile;
                            var movieSource:String = 'assets/' + cartGrid.selectedItem.moviefile;
                            // swfLoader.load(movieSource);
                            stat.load(imageSource);
                            }

                            <mx:Canvas label="Preview" showEffect="{myWL}" width="100%" height="100%" backgroundColor="#D3CDB4" borderStyle="inset" backgroundAlpha="0.5" borderColor="#020202">
                            <mx:SWFLoader id="swfLoader" y="73" x="10" showBusyCursor="true" complete="swfLoaded(event);"/>
                            </mx:Canvas> <!-- Preview -->

                            If I uncomment out the swfLoader line in the function I get an Error #1009: Cannot access a property or method of a null object reference.

                            If I pull out the code and test it - it works fine. I don't have a clue since this should be pretty basic and it's driving me crazy.

                            Another simple question, how in Flex does one get a new "compile" each time, it seems that some changes don't show up the first time the app is generated after a code change??

                            Thanks for all the help, one day I hope I can return the favor.
                            • 11. Re: Accordion/Datagrid/Master-Detail Question
                              Level 7

                              "EWN-CMI" <webforumsuser@macromedia.com> wrote in message
                              news:gjc9pq$sht$1@forums.macromedia.com...
                              > Yes, you would figure that you could reassign it, but either I didn't know
                              > how
                              > to do it (arrayCollectionvar1 = arrayCollectionvar2).

                              No, that's only going to create two arrays that point to the same array.
                              What you need to do is something like:

                              private var ac1:ArrayCollection = new ArrayCollection();
                              private var ac2:ArracyCollection = new ArrayCollection();
                              private var ac3:ArrayCollection = new ArrayCollection();
                              private var arrayToLoad:ArrayCollection;

                              private function sendService():void {
                              //do your service send here
                              ...
                              arrayToLoad = ac1;//or ac2 or ac3
                              }

                              private function onServiceResult():void{
                              arrayToLoad=event.result;
                              //whichever array you told it to load is now loaded with the result
                              }

                              But honestly I wonder if you wouldn't be better off just loading everything
                              into one ac and using a filterFunction to take the place of the WHERE
                              clause.

                              > I finally created a
                              > second connection and was able to get it to work. Thanks for the help.

                              You should probably refactor it now and fix it ;-)

                              > NOW - a really weird problem (I am so close to having this part done).
                              >
                              > // Retrieve the image associated with the item selected in the grid
                              > private function getImage():void {
                              > var cartGrid:DataGrid = dg;
                              > var imageSource:String = 'assets/' + cartGrid.selectedItem.statsfile;
                              > var movieSource:String = 'assets/' + cartGrid.selectedItem.moviefile;
                              > // swfLoader.load(movieSource);
                              > stat.load(imageSource);
                              > }
                              >
                              > <mx:Canvas label="Preview" showEffect="{myWL}" width="100%" height="100%"
                              > backgroundColor="#D3CDB4" borderStyle="inset" backgroundAlpha="0.5"
                              > borderColor="#020202">
                              > <mx:SWFLoader id="swfLoader" y="73" x="10" showBusyCursor="true"
                              > complete="swfLoaded(event);"/>
                              > </mx:Canvas> <!-- Preview -->
                              >
                              > If I uncomment out the swfLoader line in the function I get an Error
                              > #1009:
                              > Cannot access a property or method of a null object reference.
                              >
                              > If I pull out the code and test it - it works fine. I don't have a clue
                              > since
                              > this should be pretty basic and it's driving me crazy.

                              Probably a timing issue. Make sure the swfLoader actually exists before you
                              address it. Without more info on what's going on in your code, I can't
                              speculate as to what the timing issue might be.

                              > Another simple question, how in Flex does one get a new "compile" each
                              > time,
                              > it seems that some changes don't show up the first time the app is
                              > generated
                              > after a code change??

                              Check Project>Build Automatically

                              HTH;

                              Amy


                              • 12. Re: Accordion/Datagrid/Master-Detail Question
                                EWN-CMI Level 1
                                Amy, Thanks again for the help. I emailed the Google Code maintainer for FlexDB and he indicated that the way I implemented it was correct for the most part, instead of multiple connections and query objects, I just needed to reference the multiple query objects. So all is good. My limited use of FlexDB is very good versus all the other Remote amfphp methods I have looked at. I noticed on your site that you were playing around with it a time back. All one needs is a services-config.xml and the FlexDB.swc file in the libs folder and MySQL access it established.

                                My swfLoader problem was a timing problem as you suggested, I moved the initial call in my onCreateCompete from before initializing the first Accordion DataGrid to after it and it works as expected. Thanks again so much for the help.