9 Replies Latest reply on Sep 8, 2009 6:48 PM by jdesko

    Sparks ButtonBar error #1009

    jdesko Level 2

      I have an application that I am using a sparks buttonbar for it's menu.  This menu is in its own MXML module, also the dataprovider is a sparks arraycollection, I've also tried a variety of methods in populating the arraycollection whether sparks or mx I get the same results.  Everything works fine until I remove an item from the dataprovider in actionscript than I get an error #1009.  Adding an item works fine.  After removing an item and getting the error debug shows the correct items in the dataprovider and it shows the correct newindex from the indexchangevent.  I've tried the original sdk for flash builder and several diff. nightly builds including the newest.  With the original sdk using itemclick the app had error #1009 with a renderer problem.  With the new sdks error #1009 is showing null object. 


      Any suggestions or is there a better sparks component to use for an application main menu (in its own module) which items get added or removed or renamed, and the dataprovider can be an xmlcollection or arraycollection or ...?


      Thanks in advance for the help.

        • 1. Re: Sparks ButtonBar error #1009
          David_F57 Level 5

          Have you tried dettaching the dataprovider before you remove an item from the array then reattaching it ?




          [edit] remove both renderer and dataprovder.

          • 2. Re: Sparks ButtonBar error #1009
            Flex harUI Adobe Employee

            The simple remove test worked for me.  What is the full stacktrace?  Does it only fail if in a module?


            Alex Harui

            Flex SDK Developer

            Adobe Systems Inc.

            Blog: http://blogs.adobe.com/aharui

            • 3. Re: Sparks ButtonBar error #1009
              jdesko Level 2

              Sorry, I'm not sure what you mean by detaching.  I have tried ArrayCollection = new ArrayCollection and changed the data, and ArrayCollection.removeAll() then add data,  plus also ArrayCollection.DataProvider.removeItemAt() then add data and received errors listed.  I have not tried anything with the renderer directly, I thought ButtonBar would handle this, even though the original FB SDK gave me #1009 with renderer errors.


              I also have creationPolicy = all.  And I've tried ButtonBar.validateNow().  Also ButtonBar does have the method updateRenderer() but I'm not sure what to use for the renderer:IVisualElement.


              What causes me to ponder is how debug shows the correct array data and the correct index selected after changes to the arraycollection.


              Thanks again David.

              • 4. Re: Sparks ButtonBar error #1009
                David_F57 Level 5

                dataprovider = ""

                itemrenderer = null


                remove item




                • 5. Re: Sparks ButtonBar error #1009
                  jdesko Level 2

                  Thanks for the reply Alex.  I will test similar procedures in the main app later today.

                  • 6. Re: Sparks ButtonBar error #1009
                    jdesko Level 2

                    Thanks again for the help David.  I will try your suggestions, along with trying the same procedures in the main app and not a module.

                    • 7. Re: Sparks ButtonBar error #1009
                      Peter deHaan Level 4

                      I wasnt able to reproduce the problem with the following test case.


                      <?xml version="1.0" encoding="utf-8"?>
                      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                              <s:VerticalLayout paddingLeft="10" paddingTop="10" />
                          <s:ButtonBar id="btnBar" labelField="label">
                                          <fx:Object label="One" />
                                          <fx:Object label="Two" />
                                          <fx:Object label="Three" />
                                          <fx:Object label="Four" />
                          <s:Button label="add item" click="btnBar.dataProvider.addItem({label:new Date().toTimeString()});" />
                          <s:Button label="delete item" click="btnBar.dataProvider.removeItemAt(0);" />




                      • 8. Re: Sparks ButtonBar error #1009
                        jdesko Level 2

                        Thank you everyone for the replies. 


                        So I created a new stripped down project, new code, with the same file structure as the original app  - the application in the default package, menu module in a folder, and some very basic modules that the menu module loads in their own folder - and everything works.  I can add and delete buttons in the button bar from a script and no error #1009.


                        I can't tell you how many times I rewrote the original apps menu module to no avail.  Even though there is a lot of code in the original app and modules - it's always better to redo the project from scratch (I'm telling myself that to make myself feel better).


                        Peter, if you're reading, thanks for all the work on your blog (you too Alex), I visit almost daily.

                        • 9. Re: Sparks ButtonBar error #1009
                          jdesko Level 2

                          I resolved my problem with the Sparks ButtonBar.  I found when adding and removing items that I needed - requireSelection = true. 


                          If I remember correctly, if a button was removed, then you selected the last button in the bar then #1009.  For reference to explain my code, I have a menu module that has two states, each state has it's own buttonbar, and I can add up to two extra buttons, and remove one or both, depending on what is needed.  Once I paid attention to which button was selected, not by the user, but by FB after a button was removed then I understood.  Adobe does document clearly how requireSelection works.


                          My only issue now is that with requireSelect = true, after removing a button, generally the first button is than "colored" selected.  I only listen for mouse clicks so this is a visual problem for me, I liked it better when require was false then no button was "colored" selected.