Try:
var newRow:SearchInputRow = new SearchInputRow();
newRow.addEventListener("onRemoveRow",myEventHandler);
searchRows.addChild(newRow);
Tracy
________________________________
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Robert Munn
Sent: Friday, October 05, 2007 3: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>