6 Replies Latest reply on May 20, 2009 3:20 PM by Miggl

    Grid Container Events

    Miggl Level 1

      How do I go about detecting if a GridRow has been added to a Grid container? I'm assuming that I have to add an eventlistener to the Grid, but not sure which one, or if there already is a default event on the grid that handles this.

       

      Thanks!

        • 1. Re: Grid Container Events
          Gregory Lafrance Level 6

          Probably childAdd event.

           

          You may need to check the relatedObject property of the event object to see if a GridRow or GridItem was added, and not their children.

          • 2. Re: Grid Container Events
            Miggl Level 1

            That's what I was thinking. But which event do I inspect?

            • 3. Re: Grid Container Events
              Gregory Lafrance Level 6

              The event passed into the childAdd event listener function you define.

              • 4. Re: Grid Container Events
                Miggl Level 1

                Thanks again, one more step in the right direction. Now, hopefully my last question: what type of event does the childAdd event trigger?

                 

                Thanks!

                • 5. Re: Grid Container Events
                  Gregory Lafrance Level 6

                  This code should answer your question:

                   

                  <?xml version="1.0" encoding="utf-8"?>
                  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
                    <mx:Script>
                      <![CDATA[
                        import mx.controls.Button;
                        import mx.containers.GridItem;
                        import mx.containers.GridRow;
                        import mx.events.ChildExistenceChangedEvent;
                        import mx.controls.Alert;
                  
                        private function addRow():void{
                          var gr:GridRow = new GridRow();
                          for(var a:uint=0;a<4;a++){
                            var gi:GridItem = new GridItem();
                            var btn:Button = new Button();
                            btn.label = "Button" + a.toString();
                            gi.addChild(btn);
                            gr.addChild(gi);
                          }
                          myGrid.addChild(gr);
                        }
                        
                        private function addFunc(evt:ChildExistenceChangedEvent):void{
                          mx.controls.Alert.show("Row was added.");
                        }
                      ]]>
                    </mx:Script>
                    <mx:Grid id="myGrid" childAdd="addFunc(event);"/>
                    <mx:Button label="Add Grid Row" click="addRow()"/>
                  </mx:Application>
                  
                  • 6. Re: Grid Container Events
                    Miggl Level 1

                    Indeed it does! Thanks so much!