views:

45

answers:

3

I have created a custom even class which is pretty basic. But when calling an event and then relaying that event to another class I have encountered the "cannot transform thisEvent into thisOtherEvent" error.

I realize this is because I needed to override the Clone function in my custom event like so:

package com
{

 import flash.disply.*;
 import flash.events.Event;

 public class MyCustomEvents extends Event
 {

  public static const SOME_EVENT:String = "some_event";
  public var info:Object;

  public function MyCustomEvents($type:String, $info:Object,$bubbles:Boolean = false, $cancelable:Boolean = false)
  {

   super($type, $bubbles, $cancelable);
   this.info = $info;

  }

  public override function clone():Event {
   return new MyCustomEvents($type, $bubbles, $cancelable);
  }

 }
}

However I am still getting this error when I dispatch the event. Anything else I might be missing?

here is the error: TypeError: Error #1034: Type Coercion failed: cannot convert com.greensock.events::TransformEvent@d8df709 to com.customEvents.MyCustomEvents.

I tried casting the event in the code like so:

var deleteImgEvent:MyCustomEvent = new MyCustomEvent(MyCustomEvents.IMAGE_DELETE, {imgData: getImg}, true, false); this.dispatchEvent(deleteImgEvent as MyCustomEvents);

Still no luck.

UPDATE:

Ok, seems like the problem is in the greensock Transform library. When the event handler for my custom event is called, I run a function of the TransformManager class.

_manager.deleteSelection();

Inside that class it dispatched a TransformEvent. Not sure why, but it is reading that delete event as a MyCustomEvent.

A: 

Don't know if that's it but you have an extra parameter $info:Object into your custom event, but you don't pass it in your clone contructor.

return new MyCustomEvents(type, info, bubbles, cancelable);
Patrick
nope, I tried that, still getting the same error. Everywhere I read says that is all I need to do, but still not working.
pfunc
A: 

I think you need the clone function to return a MyCustomEvents type. Not an Event type. And you need to add the info parameter as stated by the previous poster.

package com {

    import flash.display.*;
    import flash.events.Event;

    public class MyCustomEvents extends Event {

    public static const SOME_EVENT:String = "some_event";
    public var info:Object;

        public function MyCustomEvents($type:String, $info:Object,$bubbles:Boolean = false, $cancelable:Boolean = false) {
            super($type, $bubbles, $cancelable);
            this.info = $info;
        }
        public override function clone():MyCustomEvents {
            return new MyCustomEvents(this.type, this.info, this.bubbles, this.cancelable);
        }
    }
}
Sandro
No, because you are overriding the Event clone() not the custom event clone. When I do this I get a incompatible override.
pfunc
A: 

http://www.bit-101.com/blog/?p=1143

http://www.kirupa.com/forum/showthread.php?p=2098265

if still no luck with this http://stackoverflow.com/questions/3585638/override-clone-in-custom-event-for-as3-need-help/3587759#3587759 then please post the code and exception output of errors you have.

thanks.

Eugene
i've read these blog posts a few times and don't see anything that I am doing differently.
pfunc
can I ask you to build some runnable example and share it, so I could help your from my IDE with your project.
Eugene
I went to build a runnable example with just a custom event, with the cloning function override and everything worked fine. So I found that the problem is in this transformmanager class. I listen for my custom event and then I run a function in the transform manager that dispatched an event as well. Somehow those are conflicting.
pfunc
great, if you able post the working code here, for others, and have a happy code :)
Eugene