# How does an event listener work?

**URL:** <https://forum.kirupa.com/t/how-does-an-event-listener-work/246653>\
**Category:** Uncategorized\
**Created:** [December 13, 2007, 5:25am UTC](https://forum.kirupa.com/t/how-does-an-event-listener-work/246653 "2007-12-13T05:25:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![digitalmatt](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/digitalmatt/32/694_2.png) [@digitalmatt](https://forum.kirupa.com/u/digitalmatt)\
**Post date:** [December 13, 2007, 5:25am UTC](https://forum.kirupa.com/t/how-does-an-event-listener-work/246653/1 "2007-12-13T05:25:50Z")

</div>

I’m having trouble finding a tutorial or article that can eloquently explain what exactly an event listener does and why it’s useful. Can anyone elaborate for me? So far this is what I understand about them:[INDENT] They’re good for making sure an event has completely occurred before a script moves on to the next procedure.  
[/INDENT]So, for example, I’m creating a flash game that sends your name and your score to a mysql database at the end of the game, then displays the top ten highest scores in the database using XML nodes. A friend of mine was saying that if I don’t use an event listener for the loadvars sendAndLoad event, that the script might move too fast before it has time to include a player’s score in the high score list (if it’s top ten) in any given game. So I think he’s right because sometimes I’ll get a high score and it won’t update in the list before I used this addEventListener. Or so I think. How can I really tell if it’s really working? Am I using the addEventListener correctly here:

```auto

// Here's where I use the LoadVars object to send the player's name and score to the database
var mySender = new LoadVars();
var myReceiver=new LoadVars();
myReceiver.onLoad = function(success) {
    if(success){
        trace("added");
    }
}
mySender.playername = _root.playername;
mySender.score = score;
mySender.sendAndLoad("addscores.php",myReceiver,"POST");
mySender.addEventListener("sendAndLoad", myReceiver.onLoad); // Am I using the addEventListener correctly?

// Here's where I grab the XML nodes from the php script....    
scores_xml = new XML();
scores_xml.onLoad = getScores;
scores_xml.load("addscores.php");
scores_xml.ignoreWhite = true;

```
