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. ![:sweat_smile: :sweat_smile:](//community.openfl.org/images/emoji/twitter/sweat_smile.png?v=5)
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! ![:smile: :smile:](//community.openfl.org/images/emoji/twitter/smile.png?v=5)
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. ![:smile: :smile:](//community.openfl.org/images/emoji/twitter/smile.png?v=5)
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! ![:smile: :smile:](//community.openfl.org/images/emoji/twitter/smile.png?v=5)
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. ![:stuck_out_tongue: :stuck_out_tongue:](//community.openfl.org/images/emoji/twitter/stuck_out_tongue.png?v=5)
But will try to do it as I intended originally. To see which one has better results!
Thanks again. ![:slight_smile: :slight_smile:](//community.openfl.org/images/emoji/twitter/slight_smile.png?v=5)
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)