6 Replies Latest reply on Feb 22, 2013 1:57 AM by pauland

    Small loop array problem

    Gug88 Level 1

      Hey guys i am reteriving a value using the getitemAt and inserting it in a loop


      Now i want to get that answer and store it in an array .I am using additemAt but it doesnt seem to be working.(probably im missing something :/) The datafield of the array where i want to save is the following

      <mx:DataGridColumn dataField="Num_Mach" headerText="Machines"/>



      the following is the code


      for (var x:int=0; x=4; x++){


                                              for (var NoMachines:int = 1; ValueRow >100 ; NoMachines++)



                                                        PartProduced = Servicetimes*NoMachines

                                                        ValueRow = 100*(ArrivalParts/PartProduced)



                                              NoMachines= NoMachines-1;







      Thanks loads

        • 1. Re: Small loop array problem

          Are you using an Array or an ArrayCollection?



          It would seem that you would want to update the Object and then put it back into the ArrayCollection.

          Then when you update the Object with your Boolean value, you can just update the ArrayCollection with myArrayCollection.setItmeAt(myObject, myLoopInt);

          • 2. Re: Small loop array problem
            Gug88 Level 1

            Thanks for the reply


            I am using an array collecion.


            Thanks for your help i tried using

            myArrayCollection.setItmeAt(myObject, myLoopInt);    But i guess im using it wrong, that do i have to subsitue myObject and MyloopInt with




            Thanks for your help

            • 3. Re: Small loop array problem
              pauland Level 4



              Your code does a lot of bad things.


              First of all variables and functions are NEVER named with a capital letter at the start - you should always use a lower-case letter at the beginning when naming variables and functions. Things that start with a capital letter are Classes or constants.


              You should never rely on the value of a loop variable when the loop has finished.


              If you are goint to add an item at a specific place you need to say where that place is.


              It's not clear if you are talking about an Array or an ArrayCollection.


              You can set an array value just by doing processAdder[someIndex] = {Num_Mach:NoMachines};


              For an ArrayCollection it's processAdder..addItemAt({Num_Mach:NoMachines}, someIndex);


              The Adobe documentation is excellent - spend some time looking at it to pick up how things work.



              • 4. Re: Small loop array problem
                DeanLoganBH Level 3

                I created a simple datagrid with an array collection.  Hopefully you can look at this an get some ideas.  I plan on getting this uploaded to my web site and explain it a little further.  Maybe even expand it a little further.


                1. Has a simple Object with 4 itmes (Number, String, String, Boolean)
                2. Object has  a create and setBoolValue functions for initial creation and updating items in an ArrayCollection
                3. Creates the ArrayCollection by generating random Objects from 2 Arrays
                4. Populates the DataGrid with the ArrayCollection
                5. A button for find the "Red" items updates the Array Collection to show which items contain "Red"
                6. A button for regenerating the random Array Collection


                You should be able to download this, unzip it and just place it in a website based folder.  The view source has been enabled, so that you can look through it.


                Simple ArrayCollection Update Example - blog post


                The example also

                1. Uses a Item Renderer for a column to change the text look for particular values
                2. Uses an Array set in the Declarations for alternating row colors in the datagrid
                3. Uses the  control bar content for placing the menu bar options in a Panel



                I just want to note that my exmple may not be the best example.  However, I was a newbie to Flex and other development before and I appreciated finding any example that would help me out.  Sometimes the offical documentation isn't very useful when you are in a hurry.  Also, I find that the only way I really understand how something works is to do an example myself. 
                • 5. Re: Small loop array problem
                  Gug88 Level 1

                  Sorry for the eyesore ! i am basically a noob but willing to learn so thanks for the tips regarding caps and so fort.

                  Thanks for the help just one last thing,Where can i find the Adobe documentation since im sure it would be of greate help.

                  Thanks again for your very usefull tips



                  • 6. Re: Small loop array problem
                    pauland Level 4

                    I typed "arraycollection" into google and this was the first link: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/collections/ArrayCol lection.html


                    This should be useful: http://www.adobe.com/devnet/flex/videotraining.html


                    Good luck.