New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modifying Sprite click handler event type sometimes throws an error #323
Comments
|
Yes, that is the best way to write it, but the fact it works in one direction and not the other is a bit confusing |
This is a bug caused by Dart's strong typing. On the first addEventListener, an EventStream is created. That same object will then be used for all CLICK events. If the function is an InputEvent, then Dart throws an exception. The lesson is -- make sure your callbacks for the same event name are all the same Event type. We fixed this in our version of EventDispatcher at the expense of making multiple EventStream based on type. |
I will take a look at it! Thanks for reporting this issue |
Found another issue that might be related. Consider the following code: void main()
{
GlassPlate plate = new GlassPlate(200, 200);
// ..addEventListener(MouseEvent.MOUSE_DOWN, _handleMouseDown);
plate.removeEventListeners(MouseEvent.MOUSE_DOWN);
plate.removeEventListener(MouseEvent.MOUSE_DOWN, _handleMouseDown);
}
void _handleMouseDown(InputEvent event)
{
print('handling mouse down');
} Running as is tosses a |
The following code throws an error after clicking the sprite when it goes to add the second event listener.
Uncaught Error: Type 'EventStream<Event>' should be 'EventStream<InputEvent>' to implement expected type 'EventStream<InputEvent>'.
Both click handler methods standalone seem to work fine.
In this issue, it seems like it's hanging onto the original event handler type.
If I reverse the order (handle with InputEvent first, then on second click handle with Event), it seems to work fine.
Wondering if this is a StageXL bug, or if I'm just coding improperly (entirely possible).
The text was updated successfully, but these errors were encountered: