title: How do I dynamically add an object to my Flex 3 Array Collection?
body: <p>I have thoroughly searched, but have not found an answer to this question. Maybe my question is wrong. I have a total of 30 Children on each Canvas child of my tabNavigator. The code works well for counting and iterating through the children, but when I attempt to add an item to my ArrayCollection, it all falls apart. Here's the code:</p>
  
  <pre><code>    private function addrNewDB():void {
          var q:int = 0;
          var t:int = tabNavigator.numChildren;
  
      while (q&lt;t){
              var TNG:Array = tabNavigator.getChildren();
  
              var qnn:Array = TNG[q].getChildren() as Array;
              var gat:int = 0;
              var pat:int = TNG[q].numChildren;
              var newItem:Object = new Object();
  
              while (gat&lt;pat){
  
                  if (UIComponent(qunn[gat]) is CheckBox){
                      if (qunn[gat].selected == true){
                          var game:String = "Y";
                      }
                      else {
                          gm = "N";
                  }
              Alert.show("gat: "+String(gat)+" | pat: "+String(pat)+"\n"+qnn[gat].id+" - "+qnn[gat].label+": "+gm);
  
  
              }           
                  gat++;
              }
          q++;
          }
      }
  </code></pre>
  
  <p>What's going on here is that I have tabs that are dynamically added at runtime with a button. Each tab has a canvas upon which are textboxes, labels, checkboxes, and a combobox. There are 30 items in total; seven of them are checkboxes. </p>
  
  <p>I have set up this code to iterate through each child (component) of each Canvas child (pat) of each Tab(t) in my tabNavigator, determine if the component is a CheckBox, see if it is selected, and then Alert me for only the 7 CheckBoxes on each Canvas. </p>
  
  <p>All of this works well. Where I run into a snag is when I attempt to add the new item to the HardwareItems ArrayCollection. </p>
  
  <p>I think that I am just not getting the syntax right. When I try to place some code to add a new item to HardwareItems right after the Alert, it stops Alerting me after the first CheckBox, so I am assuming that it is running into an issue of some kind with the way I've been coding it.</p>
  
  <p>What I would like is some help in correctly adding a new item to the HardwareItems array collection for each of the 7 checkboxes. </p>
  
  <p>I have tried this:</p>
  
  <pre><code>HardwareItems.addItem({merch: lblMerchID.text, 
                                 item: qnn(gat).label, 
                                 manf: "", 
                                 have: gm, 
                                 requ: "", 
                                 qual: "", 
                                 location: "", 
                                 id: qnn(gat).id});
  </code></pre>
  
  <p>and this:</p>
  
  <pre><code>                newItem['merch'] = lblMerchID.text;
                  newItem['item'] = qnn(gat).label;
                  newItem['qual' = "";
                  newItem['loc'] = "";
                  newItem['id'] = qnn(gat).id;
  
                          HardwareItems.addItem(newItem);
                          HardwareItems.refresh();
  </code></pre>
  
  <p>and this too:</p>
  
  <pre><code>                newItem.merch = lblMerchID.text;
                  newItem.item = qnn(gat).label;
                  newItem.qual = "";
                  newItem.loc = "";
                  newItem.id = qnn(gat).id;
  
                          HardwareItems.addItem(newItem);
                          HardwareItems.refresh();
  </code></pre>
  
  <p>It's obvious that these are all incorrect ways to accomplish what I want, but I'm just trying anything. Incidentally, none of these coding atrocities threw any errors. When I tried them, though, I got one alert... the first CheckBox which is at 23 out of 30 items. </p>
  
  <p>I've read up on all the documentation about ArrayCollection and Array syntax, and I guess I just don't get it. Any help is appreciated. Thank you.  </p>