I have problem with casting custom event currentTarget to component. When I’m trying to removeElement from its parent container i get error. What’s the deal?
TypeError: Error #1034: Type Coercion failed: cannot convert mx.events::FlexEvent@8811c41 to com.modultek.pis.itemmachine.search.events.SortEvent.
private function sortSelection_removeHandler(event:SortEvent):void
{
var sortSelection:SortSelection = event.currentTarget as SortSelection;
this.removeElement(sortSelection);
}
Component will be removed but I get this error.
your problem is not in the
var sortSelection:SortSelection = event.currentTarget as SortSelection;line at all.Read the Error message carefully. It tells you that there is an invalid cast from
FlexEventtoSortEvent, which happens onChange
event:SortEventin the function signature toevent:FlexEventorevent:Event