# Newbie: eventListeners and functions problem

**URL:** <https://forum.kirupa.com/t/newbie-eventlisteners-and-functions-problem/269785>\
**Category:** flash\
**Created:** [September 1, 2008, 5:44pm UTC](https://forum.kirupa.com/t/newbie-eventlisteners-and-functions-problem/269785 "2008-09-01T17:44:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![zerosum](https://avatars.discourse-cdn.com/v4/letter/z/b2d939/32.png) [@zerosum](https://forum.kirupa.com/u/zerosum)\
**Post date:** [September 1, 2008, 5:44pm UTC](https://forum.kirupa.com/t/newbie-eventlisteners-and-functions-problem/269785/1 "2008-09-01T17:44:01Z")

</div>

Hi there,

I have a noob question that annoys me.  
I want to calculate the speed of the mouse. For that, I register when the mouse is clicked, get the mouseX, mouseY, and then add an event listener that subtracts the new x,y values from the old, and then I sqrt to get the distance, which is a vector I can use. All good.

But, I am new to AS 3 and I cannot figure out the whole event listeners thing: I write an EnterFrame event that acts as main loop, then I write a MouseEvent that captures the click, and launches another EnterFrame where I calculate the positions. But it doesn’t work - it returns NoN all the time.

I can imagine it is a scope problem, but I am not sure how to fix it - any help will be appreciated.

Thanks!!
