Code Monkey home page Code Monkey logo

Comments (22)

Hasufel avatar Hasufel commented on June 24, 2024

This behavior is normal in Flash - so it should be as well in HTML5 - you can register as many times as you want a listener with same event and same dispatcher. Regarding the hasEventListener however, I don't know :)

from nme.

glantucan avatar glantucan commented on June 24, 2024

Some test code:

function init() 
{
    if (inited) return;
    inited = true;

    display = new Sprite();

    display.graphics.beginFill(0x778855);
    display.graphics.drawCircle(0, 0, 30);
    display.graphics.endFill();
    display.x = 200;
    display.y = 300;
    addChild(display);
    display.name = "circle";


    trace("Has display a MOUSE_DOWN listener? " + display.hasEventListener(MouseEvent.MOUSE_DOWN));
    display.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
    trace("Has display a MOUSE_DOWN listener? " + display.hasEventListener(MouseEvent.MOUSE_DOWN));

    if (display.hasEventListener(MouseEvent.MOUSE_DOWN)) {
        trace("Trying to remove it");
        display.removeEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
    }
    // The listener was actaully removed, if we stop here the handler is never called. That means removeEventListener works.
    trace("Should be false, but returns: " + display.hasEventListener(MouseEvent.MOUSE_DOWN));
    //Adding it again
    display.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
    // And again
    display.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
}


private function onMouseDown(e:MouseEvent):Void 
{
    display.removeEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
    display.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
    display.scaleX = display.scaleY = 1.2;
    trace("  MOuseDown:              " + e.target.name);
}

private function onMouseUp(e:MouseEvent):Void 
{
    display.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
    display.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
    display.scaleX = display.scaleY = 1.1;
    trace("  MOuseUp:      " + e.target.name);
}

from nme.

glantucan avatar glantucan commented on June 24, 2024

No. that's not normal behaviour in flash. If you try to add the same listener for the same event, to the same dispatcher, the addEventListener call is just ignored, (unless the priority or useCapture parameters are different).

from nme.

Hasufel avatar Hasufel commented on June 24, 2024

Just try it.

from nme.

glantucan avatar glantucan commented on June 24, 2024

I did
The previous code only makes only one call to the onMouseDown() function when targeting flash and two when targeting html5
At least in my system

from nme.

Hasufel avatar Hasufel commented on June 24, 2024

Try ENTER_FRAME :)

from nme.

glantucan avatar glantucan commented on June 24, 2024

I've just had a look to browser.events.EventDispatcher, and I think the removeEventListener is not doing anything to remove the listener from the nmeEventMap property.

public function removeEventListener(type:String, listener:Dynamic->Void, inCapture:Bool = false):Void {

    if (!existList(type)) return;

    var list = getList(type);
    var capture:Bool = (inCapture == null ? false : inCapture);

    for (i in 0...list.length) {

        if (list[i].Is(listener, capture)) {

            list.splice(i, 1);
            return;

        }

    }

}

list.splice(i, 1) just removes the listener from the local var

That's probably the reason hasEventListener() falis and addEventlistener() too, cause it uses nmeEventMap find out if the listener is already there

I'm not an expert but I think that's what's happening.

from nme.

glantucan avatar glantucan commented on June 24, 2024

I just tried with ENTER_FRAME. The listener is not duplicated neither in flash or html5 targets:
Test code:

    //...
    display.addEventListener(Event.ENTER_FRAME, onFrame);
    display.addEventListener(Event.ENTER_FRAME, onTestFrame);
    display.addEventListener(Event.ENTER_FRAME, onTestFrame);
}

private function onTestFrame(e:Event):Void 
{

    trace(_numFrame);
}

private function onFrame(e:Event):Void 
{
    _numFrame++;
}

from nme.

Hasufel avatar Hasufel commented on June 24, 2024

try in flash, mac, android, windows, ios... it will duplicate.

from nme.

glantucan avatar glantucan commented on June 24, 2024

Odd ;P
Are we using the same version of NME?
Mine is 3.5.5

from nme.

glantucan avatar glantucan commented on June 24, 2024

Opps!
I pressed the wrong button

from nme.

glantucan avatar glantucan commented on June 24, 2024

By the way whats the difference between this site and the one in https://haxenme.atlassian.net/secure/Dashboard.jspa. Just found it googling for similar issues

from nme.

Hasufel avatar Hasufel commented on June 24, 2024

Just tested on my side. It does duplicate on mac/android but not in flash (could test only those quickly now) - odd, it should, as this is the way flash should work. In either cases, something's fishy.

from nme.

glantucan avatar glantucan commented on June 24, 2024

I don't really think that's the way it should work API documentation says:

"Keep in mind that after the listener is registered, subsequent calls to addEventListener() with a different type or useCapture value result in the creation of a separate listener registration. For example, if you first register a listener with useCapture set to true, it listens only during the capture phase. If you call addEventListener() again using the same listener object, but with useCapture set to false, you have two separate listeners: one that listens during the capture phase and another that listens during the target and bubbling phases."

And, though I'm not completely sure, I think last time I checked this behaviour on flash I decide it was not necessary to use hasEventListener() to check wether the dispatcher had already a listener for an event to avoid the risk uf registering the same listener again.

Anyhow, not a big deal if I have to use hasEventListener() to be sure, The problem is that it isn't working either

from nme.

Hasufel avatar Hasufel commented on June 24, 2024

it used to be like that in Flash back in the days... You could add and add and add. I'm using NME 4.x (source) under OpenFL. Confirmed flash doesnt add, but mac/android do.

from nme.

crayfellow avatar crayfellow commented on June 24, 2024

hi guys, should this be in the openfl-html5 repository issues? Also FYI, the JIRA site (https://haxenme.atlassian.net) was our attempt to consolidate issue tracking.

from nme.

glantucan avatar glantucan commented on June 24, 2024

I guess it should be there too, for what hasufel says it's happening with openfl too.

Ok, I also posted the issue there, it's a little bit confusing to have several places for issue tracking.

from nme.

crayfellow avatar crayfellow commented on June 24, 2024

yup. I am thinking it is probably better to standardize on github issues now. I added my note only to let you know why the JIRA site existed. Either way going forward if there are HTML5 issues the report and the resulting fix should be in openfl-html5 as that is where the code now lives that once was NME html5.

from nme.

glantucan avatar glantucan commented on June 24, 2024

Don't understand very well. Do you mean NME is not going to be updated anymore?
I am new to haxe and NME and as you probably noticed ;)
I believe haxe 3 and openfl is the recommended way of doing things, but as I can't find much documentation for it I chose to start with haxe 2.10 and NME.
Did I made the wrong choice?

from nme.

tvalentius avatar tvalentius commented on June 24, 2024

@glantucan have you try the OpenFL yet? it's pretty much same with NME , i tried to compile/build my NME/Haxe 2.10 project with OpenFL and it runs smoothly.

If you are looking for stability, i suggest you use OpenFL

from nme.

thomasuster avatar thomasuster commented on June 24, 2024

@glantucan Is this still an issue?

from nme.

thomasuster avatar thomasuster commented on June 24, 2024

stale

from nme.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.