0

I have an event listener for a custom event type. This custom event overrides the clone method as required.

In this event listener I want to dispatch an instance of a different type of event... a different custom event instance altogether. It also overrides the clone method as required.

The problem is I'm getting a type coercion error: TypeError: Error #1034: Type Coercion failed: ...

I do not know what is trying to do the casting. My code is:

/* elsewhere in a method */
addEventListener(GestureEvent.GESTURE_SCALE, handlePinched);

/* the event handler */
private function handlePinched(e:GestureEvent):void
{
    dispatchEvent(new BezelEvent( BezelEvent.PINCH, e ));
}

BezelEvent.PINCH evaluates to "__bezel_event_pinch" which is a unique string that isn't colliding with other events.

And yet, I'm getting this type coercion... Yes, it's in a "dispatchEvent loop" handling an event, but dispatching a different event based on some event seems like a SUPER common and trivial scenario. Can anyone figure out why it's trying to convert my new BezelEvent instance to a GestureEvent instance??

1 Answer 1

0

Silly silly silly...

The answer: Make sure your eventHandlers listening for the new event are expecting the right event type.

My handler for the BezelEvent event was defined as expecting a GestureEvent. Changing the handler to expect BezelEvent fixed the problem.

Let me daftness save you some time.

sigh

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.