Comments (22)
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.
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.
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.
Just try it.
from nme.
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.
Try ENTER_FRAME :)
from nme.
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.
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.
try in flash, mac, android, windows, ios... it will duplicate.
from nme.
Odd ;P
Are we using the same version of NME?
Mine is 3.5.5
from nme.
Opps!
I pressed the wrong button
from nme.
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.
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.
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.
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.
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.
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.
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.
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.
@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.
@glantucan Is this still an issue?
from nme.
stale
from nme.
Related Issues (20)
- relatively rare timer crash. can't get why yet HOT 7
- [QUESTION] How accurate cubicTo method? HOT 2
- Issue with clipboard getdata on Android HOT 2
- Window close events
- Incompatibility with SWF library HOT 4
- Unable to run sample project on Linux HOT 3
- nme setup fails on M1 Mac
- CapabilitiesGetScreenDPI on Mac retina display concern HOT 8
- Video player on android 11 issue HOT 1
- nme build is adding empty `-cp`s
- Build Error: Invalid character: / HOT 3
- nme build neko create an empty output file.
- xcode 14.0.1 NME app hang risk warning
- Cant compile NME for android with latest hxcpp changes
- nmehost download site has been taken over, please do not visit till Hugh has resolved. HOT 1
- ByteArray writeFile doesnt work on iOS
- Android not working? HOT 9
- Exception: ZLib Error : incorrect header check(-3) HOT 1
- linux jsprime HOT 1
- [Windows] TextField does not work properly with input method
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nme.