Skip navigation
Gug88
Currently Being Moderated

Small loop array problem

Feb 21, 2013 4:41 AM

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++){

                                        Servicetimes=int(ProcessAdder.getItemAt(x).Servic e_Rate)

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

                                        {

 

                                                  PartProduced = Servicetimes*NoMachines

                                                  ValueRow = 100*(ArrivalParts/PartProduced)

 

                                        }

                                        NoMachines= NoMachines-1;

 

     ProcessAdder.addItemAt({Num_Mach:NoMachines});

 

                              }

 

 

Thanks loads

 
Replies
  • Currently Being Moderated
    Feb 21, 2013 8:21 AM   in reply to Gug88

    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);

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 21, 2013 8:46 AM   in reply to DeanLoganBH

    Gug88,

     

    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.

     

    Paul

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 21, 2013 4:48 PM   in reply to Gug88

    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. 
     
    |
    Mark as:
  • Currently Being Moderated
    Feb 22, 2013 1:57 AM   in reply to Gug88

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

     

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

     

    Good luck.

     

    Paul

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points