Hi!
I’m writing this one since I didn’t find an answer to this in the forums, so sorry if this has already been asked before.
In a mouse up event handler for a sprite, if I trace the value for “e.currentTarget.x” or “e.currentTarget.y”, while using the Flash or Windows targets, I get the correct X/Y values. But if I use the HTML5 or Neko targets, all I get are null values for both, even though tracing “currentTarget” returns “[object Sprite]”.
For now, all I’m doing is this:
function testclicks( e:MouseEvent ):Void
{
trace( e.currentTarget );
trace( e.currentTarget.x );
trace( e.currentTarget.y );
}
Am I doing something wrong here? Should I store these values somewhere else?
Thanks!
Ended up using a similar approach to the one used in the PiratePig example project (since I’m making a small puzzle, tried reading full code to build my own version ).
Still, if somebody could answer why object properties are either null or 0 in html5, I’d be really thankful.
You can access the properties of the currentTarget in neko/html5 when you cast it to its type:
trace(cast(e.currentTarget, DisplayObject).x);
this works, but why this is necessary when targeting neko/Html5 I don’t know neither
2 Likes
Oh, thank you!
I thought it was a little bit strange the first time I tried accessing the properties. Tried adding properties to the object and copying the values in those properties but also didn’t work.
In the end, I just used the location of the mouse pointer (like in PiratePig) relative to the sprite in the stage.
But will try to do it as I intended originally. To see which one has better results!
Thanks again.
Hi
Sometimes it is very necessary to access the currentTarget (and its properties).
When you want the re-use the same handler function for many different objects
(objects that are created at runtime in a loop for example)