2012-03-21 13 views
0

カスタムイベントcurrentTargetをコンポーネントにキャストする際に問題があります。親コンテナからremoveElementを削除しようとすると、エラーが発生します。どうしたんだ?動的に作成されたコンポーネントが原因でエラーが発生する

TypeError: Error #1034: Type Coercion failed: cannot convert mx.events::[email protected] 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); 
} 

コンポーネントは削除されますが、このエラーが発生します。

答えて

2

問題はvar sortSelection:SortSelection = event.currentTarget as SortSelection;行にはまったくありません。

エラーメッセージをよく読んでください。それはevent:FlexEventに関数のシグネチャで

private function sortSelection_removeHandler(event:SortEvent):void 

変更event:SortEventまたはevent:Event

+0

いいえ。イベントにデータを追加する必要がある場合、FlexEventはそれをサポートしていません。 –

0

問題私は上のイベント宣言を持っていなかったということであったに起こるSortEventからFlexEventから無効なキャストが、そこにあることを示しています私のディスパッチクラス。

[Event(name="remove" , type=".....search.events.SortEvent")] 
関連する問題