(BUG?) Stage::Event.ADDED -> event.target = Stage (HTML5 Only)

Hey guys,

Sorry if this has been posted before - I couldn’t find it.

I’ve been trying to catch all instances added to the display list, but have come across this problem when targeting HTML5 (tested and works fine for flash and windows).

stage.addEventListener(Event.ADDED, handleAdded);

function added(event:Event):Void
{
    trace(event.target);        // Stage (in flash and windows its the object being added as expected).

    trace(event.currentTarget); // Stage (as expected)
}

Any thoughts and or workarounds would be much appreciated.

Many thanks!

Is this wrong for all objects or only sometimes?

Hi, thanks for getting back.

So far it has been the case for all the objects I have tried. So far these have all extended openlfl.display.Sprite.

Cheers.

Should be fixed, thank you! :smile:

Wow thanks man, that was quick! :slight_smile:

I think this bug has opened again in html5 target? I can see that at openfl 4.2.0 at least.

Does the same sample code above recreate it for you, or would we need to run different code to recreate the issue? Thanks :slight_smile:

I’ve created a simple project like sample code above, it worked as expected in html5, so, I think that the bug in StablexUI
thank you

Hello, bug still persists and I need fast fix!!! Probably its new bug.
here is how to reproduce:
It looks like events don’t shoot if I add to stage Element(extended by Sprite) , which already contains elements inside

Switch addChild and f.addChill lines to see difference


class Main extends Sprite 
{
    public function new() 
    {
        super();        
        var s = new Element();
        var f:Sprite = new Sprite();           
        addChild(f);        
        f.addChild(s);  // try switching with line above
    }
}

class Element extends Sprite 
{
    public function new() 
    {
        super();
        this.addEventListener(Event.ADDED_TO_STAGE, init);
    }
    
    function init(?e:Dynamic) 
    {
        this.graphics.beginFill(0x2E4AAB);
        this.graphics.drawRect(0, 0, 250, 150);
    }    
}

openfl=4.3.1
lime=3.3.0
haxe=3.2.1