Event bubbling not working correctly

Hi,
I have a problem: targeting Flash my eventListener intercepts the event and I can access public properties of the event.target, while targeting HTML5 target properties are null, as if they weren’t been set/instanced already.
The eventListener has been added to the Sprite containing the objects that trigger the event, a very simple situation.

This looks like a bug in the bubbling process.

EDIT:

  • targeting Flash event.target is the item in the container and event.currentTarget is the container
  • targeting HTML5 event.target and event.currentTarget are both the container
    ???

Do you have a simple test case?

Too complex to write here, how can I send zip files?

When exporting to HTML you have to cast ‘currentTarget’ to the properties base class (or actual class) to access them.

e.g. in an eventHandler

event.currentTarget.x  -> null in HTML/neko
cast(event.currentTarget, DisplayObject).x -> gives the correct value

could that be the case for your problem?

Well, no, target and currentTarget are different types, not related: they are both Sprite extensions, but I need the properties of the subclasses.

Looking at your sample code, I’m not immediately sure how we can more closely replicate what you have.

// from object

anotherObject.addEventListener ("customEvent", myListener);

// from anotherObject

dispatchEvent (new Event ("customEvent"));

If I understand properly, a custom event like this is dispatching in OpenFL with both target and currentTarget set to anotherObject, while Flash uses object as the event target

There is actually no reference to object in either of these above, but Flash is detecting that myListener occurs within the scope of the object instance. In Haxe, I believe that passing a function reference, we do not have access to the parent class instance that contains that function reference. Am I wrong?

Since we are not running in a Flash virtual machine, we might not have access to this knowledge, but could this be worked around by using this instead of event.target?

Please let me know, guys, if I seem to be understanding, and if there is a way to find a class instance from a method reference. I think we work around this with the core events (mouse, key, etc) because we are manually walking through, and can get the target object, but in the above, I’m not sure where we would get it

An example:
I am in SpriteX: in SpriteX stage I add the child SubSpriteX, and in this one I add the Sub-SubSpriteX, so I have this structure in the DisplayList

SpriteX
	- SubSpriteX
		- Sub-SubSpriteX0
		- Sub-SubSpriteX1
		- Sub-SubSpriteX2
		- etc...

SpriteX adds the listener to SubSpriteX to listen to events dispatched by the Sub-SubSpriteX

SpriteX
	- SubSpriteX-> listener
		- Sub-SubSpriteX0
		- Sub-SubSpriteX1 <-event
		- Sub-SubSpriteX2
		- etc...

This way event.currentTarget is the object I directly attached the listener to, in this case SubSpriteX, while event.target is the object that actually dispatched the event, in this case Sub-SubSpriteX, but could be also a subobject of Sub-SubSpriteX.

The event bubbling throughout the displayList should keep in target the reference to the object that dispatched it .

trace("event.target " + event.target);
trace("event.currentTarget " + event.currentTarget);

Flash - correct

event.target [object Sub-SubSpriteX]
event.currentTarget [object SubSpriteX]

HTML5 - wrong

event.target [object SubSpriteX]
event.currentTarget [object SubSpriteX]

EDIT: in the latest release the event.target problem has been fixed definitively, thank you Joshua!

1 Like