2 Replies Latest reply on Dec 9, 2009 5:13 AM by julien.63

    Why event type coercion failed ?




      I have a component which is basically a canvas with an image.

      I would like to dispatch a custom event when clicking on the image.


      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="200" height="200">
                     import app.events.TypeIconEvent;
                     public var iconSource:String;
                     private var _name:String;
                     private var _id:Number;
                     private function onClick(evt:MouseEvent):void{
                          var e:TypeIconEvent = new TypeIconEvent(TypeIconEvent.CLICK,this._name, this._id);
           <mx:Image id="image" source="{iconSource}" click="{onClick(event);}" />


      but I have the error message saying :

      TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::MouseEvent@2925f51 to app.events.TypeIconEvent.



      I'm not trying to cast the MouseEvent. I'm creating a brand new TypeIconEvent and dispatching it, so I don't understand what's the issue?



      Here below is the code for the custom event :

      // ActionScript file
      package app.events{     
           import flash.events.Event;
           public class TypeIconEvent extends Event{
                public static const CLICK:String = "click";
                private var typeName:String;
                private var typeID:Number;
                public function TypeIconEvent(type:String, typeName:String, typeID:Number):void{
                     this.typeName = typeName;
                     this.typeID = typeID;
                override public function clone():Event{
                     return new TypeIconEvent(this.type, this.typeName,this.typeID);