you can write your class that way, but then there is only one listener?

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Ralf Bokelberg
Sent: Sunday, October 07, 2007 4:01 AM
To: [email protected]
Subject: Re: [flexcoders] adding an event listener to a dynamically
added component



Wouldn't it be nice, if the compiler allowed to assign a function to
onRemoveRow 
and replace it by addEventListener(...)?

Cheers
Ralf.  


On 10/6/07, Robert Munn <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> > wrote: 

        That was easy, thanks Alex!
        
        BTW, I had to cast the target on the remove function to avoid an
implicit coercion error:
        
             searchRows.removeChild(DisplayObject(e.target));
        
        
        Rob

        
        
        
        
        On 10/5/07, Alex Harui <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> > wrote: 

                

                               var newRow:SearchInputRow = new
SearchInputRow(); 
                
                

                newRow.addEventListener("onRemoveRow", removeRow);

                
                               // add the new component to the VBox 
                                searchRows.addChild(newRow);
                  

                private function removeRow(event:Event):void

                {

                            searchRows.removeChild(event.target);

                }

                
________________________________


                From: [email protected] [mailto: flexcoders@
<mailto:flexcoders@> yahoogroups.com <http://yahoogroups.com> ] On
Behalf Of Robert Munn
                Sent: Friday, October 05, 2007 12:17 PM
                To: flexcoders
                Subject: [flexcoders] adding an event listener to a
dynamically added component

                 

                I have a search component that allows the user to add
new search criteria on the fly. The search criteria is contained in a
custom component, one row per criteria. The first row is defined like
this:
                
                <c:SearchInputRow
onCriteriaChange="doCriteriaChanged(event)" removeButton="false"/> 
                        
                Rows can be added by clicking a button which dynamically
adds a new component like so:
                
                                var newRow:SearchInputRow = new
SearchInputRow(); 
                
                               // add the new component to the VBox 
                                searchRows.addChild(newRow);
                        
                
                The custom component has a button that can be used to
remove any rows after the first row. The button calls a function that
dispatches a custom event called onRowRemove 
                
                                private function doRemoveRow():void{
                                    var e:Event = new
Event("onRemoveRow",true);
                                    trace(e);
                                    dispatchEvent(e);        
                
                                }
                                            
                    <mx:Metadata>
                        [Event(name="onRemoveRow")]
                    </mx:Metadata>
                
                The event fires, but my dynamically added rows never see
it because they are not listening for it. How can I add an event
listener for this custom event to my dynamically created components? 
                
                
                Thanks in advance,
                
                Rob
                
                -- 
                ---------------
                Robert Munn
                www.emergentpath.com <http://www.emergentpath.com>  

                

                




        -- 
        ---------------
        Robert Munn
        www.emergentpath.com <http://www.emergentpath.com> 

        

        




-- 
Ralf Bokelberg <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> >
Flex & Flash Consultant based in Cologne/Germany
Phone +49 (0) 221 530 15 35 

 

Reply via email to