views:

28

answers:

2

This is the strangest most unexplainable and frustratng thing I've experienced with flash and I have no Idea how to solve the problem.

Consider this function

public function trackDownloadHandler(event:MP3DownloadEvent):void
  {
   dispatchEvent(event);
   //dispatchEvent(new MP3DownloadEvent(MP3DownloadEvent.OPEN,event.channelPadID))
  }

I've done this a million times. A particular event arrives in a handler had a dispatch it again from the class it arrived to.

But for some bizarre reason I'm getting an error saying

TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::Event@a06ebe1 to com.rocudo.audioEngine.events.MP3DownloadEvent.

I don't see where I'm trying to convert anything anywhere?

So I tried next to maybe just dispatch a brand new event instead and see how that worked out. The implementation is here below.

public function trackDownloadHandler(event:MP3DownloadEvent):void
  {
   //dispatchEvent(event);
   dispatchEvent(new MP3DownloadEvent(MP3DownloadEvent.OPEN,event.channelPadID))
  }

But in that case the original type error message goes away and I get a new error saying

Type was not found or compile time constant :Vector

What the hell is going on ??

A: 

Maybe it's in the event dispatch that calls trackDownloadHandler(event:MP3DownloadEvent)? If you're just dispatching a vanilla Event, then the error you're getting would make sense.

Marcus
Thanks for the replies. I'm actually coding in flex builder with the compiler set 10.0.0 so I really dont get the vector error at all?I didnt add the code for my custom event but it does in fact override the clone method. Also I am deffinately not just dispatching an ordinary event.I just doesnt make sense but I guess I have to of over looked somethingI'll dig around this a little more in the morning..... I am very confused though 0-o.
dubbeat
+2  A: 

I think the problem may be with not having a clone method defined in your custom MP3DownloadEvent.

Adobe Livedocs flash.events.Event clone()

Returns a new Event object that is a copy of the original instance of the Event object. You do not normally call clone(); the EventDispatcher class calls it automatically when you redispatch an event—that is, when you call dispatchEvent(event) from a handler that is handling event.

For your Vector error, I believe Vectors are only available in CS4. So, if you are using code written for CS4 (and using Vecotrs), and you are compiling with CS3, you would likely get an error like this.

sberry2A
I agree with sberry2A - override the clone method on your custom event class, and dispatch e.clone(). Although, the second approach you mentioned works, creating a new one, and that Vector error is likely to be due to what sberry2A mentions. Just be aware that at some point you'll have to remove the event listener otherwise you'll run into an event dispatch recursion overflow.
falomir