For some reason, when I click on my button in my game engine, an error is thrown basically saying “Cast invalid”:
The code in question is this:
onChoiceClicked.dispatch(cast (e.target, ChoiceButton).Code);
This is an MSignal event that is supposed to dispatch the Code string variable within the target (which is a type ChoiceButton, hence the cast). This works in Flash just fine, but Windows doesn’t like it. I haven’t tried neko yet, but both are C++ so I have no doubt it will throw the same error at me.
When this is dispatched, whatever is in the Code variable is run by the HScript parser and (with any luck) will move onto the next bit of dialogue. As you can tell this is a visual novel.
What do you think is the problem with this cast and why the windows target doesn’t like it?
Nevermind, e.currentTarget worked…
This might also be fixed with the latest OpenFL, which has an event.target specific bug fix
Awesome! Glad to hear, although I don’t suppose there is much of a difference between target and currentTarget?
It depends, let’s say you have a button with graphics on the inside. With
mouseChildren = false the
currentTarget should both be the button. However, with
mouseChildren = true you might get the
target value as some graphic inside the button. This is what you “really” clicked on. The
currentTarget is still the button itself, because the event bubbled up and that is where your listener caught the event
The above scenario should have already been good, but dispatching a custom event didn’t always set the
target field properly while bubbling
I suppose (thinking aloud, now) that you might just need a
mouseChildren = false on your button to have consistent behavior
Ah, okay. That makes more sense now. Thank you.