self Kill EventListener ? (SOLVED)

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,440
First Language
French
Primarily Uses
RMMV
hi it is possible to self kill a EventListener ?
If yes how i can performe this ?

example:
PHP:
    vidControl.vIntro.addEventListener("timeupdate", function() { 
        if (this.currentTime > 10) {
            //Do Stuff one time
            this.removeEventListener('timeupdate',this); // And Do Self KILL, BREAK or DESTROY ?
        }
    }, false);
thank
 

LTN Games

Indie Studio
Veteran
Joined
Jun 25, 2015
Messages
704
Reaction score
631
First Language
English
Primarily Uses
RMMV
Try putting the function in a variable and using that to add and remove the listener, I don't think you can remove an event listener if it's an anonymous function.

I'd type some code for you but I am on mobile phone. :/
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,440
First Language
French
Primarily Uses
RMMV
Try putting the function in a variable and using that to add and remove the listener, I don't think you can remove an event listener if it's an anonymous function.

I'd type some code for you but I am on mobile phone. :/
humm something like thats ?
i give name to the anonyme function in the listener, then remove it when the function has run:
PHP:
    vidControl.vIntro.addEventListener("timeupdate", function TESTT() {
        if (this.currentTime > 10) {
            //Do Stuff one time
            this.removeEventListener('timeupdate',TESTT); // work! But is this the right way to do it? 
        }
    }, false);
 

LTN Games

Indie Studio
Veteran
Joined
Jun 25, 2015
Messages
704
Reaction score
631
First Language
English
Primarily Uses
RMMV
That is one way of doing it, absolutely, this works for you correct? My initial thought was to assign it to a variable but the way you did it should work fine. There is no one way of doing things, there is usually plenty of ways to achieve the same result.
Code:
// My initial thought was....

var updateTimeCall = function () {
//Do stuff and remove listener by refrencing the variable name
removeEventListener('event', updateTimeCall)
}
addEventListener('event', updateTimeCall)
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,440
First Language
French
Primarily Uses
RMMV
That is one way of doing it, absolutely, this works for you correct? My initial thought was to assign it to a variable but the way you did it should work fine. There is no one way of doing things, there is usually plenty of ways to achieve the same result.
Code:
// My initial thought was....

var updateTimeCall = function () {
//Do stuff and remove listener by refrencing the variable name
removeEventListener('event', updateTimeCall)
}
addEventListener('event', updateTimeCall)
yes is work
i found tips in this article
https://www.broken-links.com/2013/05/22/removing-event-listeners-with-anonymous-functions/
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

I should realize that error was produced by a outdated version of MZ so that's why it pop up like that
Ami
i can't wait to drink some ice after struggling with my illness in 9 days. 9 days is really bad for me,i can't focus with my shop and even can't do something with my project
How many hours have you got in mz so far?

A bit of a "sparkle" update to the lower portion of the world map. :LZSexcite:
attack on titan final season is airing tomorrow, I'm excited and scared at the same time!

Forum statistics

Threads
105,882
Messages
1,017,231
Members
137,607
Latest member
Maddo
Top