# Zombie Related Question Part II

**URL:** <https://forum.kirupa.com/t/zombie-related-question-part-ii/216869>\
**Category:** flash\
**Created:** [February 21, 2007, 5:23am UTC](https://forum.kirupa.com/t/zombie-related-question-part-ii/216869 "2007-02-21T05:23:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rizzex123](https://avatars.discourse-cdn.com/v4/letter/r/dec6dc/32.png) [@rizzex123](https://forum.kirupa.com/u/rizzex123)\
**Post date:** [February 21, 2007, 5:23am UTC](https://forum.kirupa.com/t/zombie-related-question-part-ii/216869/1 "2007-02-21T05:23:40Z")

</div>

I am creating an eventListener class that records the x and y positions of the mouse cursor whenever a user clicks someplace on the screen. This gets called every frame.

For some reason, the variable I am using to record the X position of each mouse click, cursorXPos , keeps coming up as being “undefined”. I can’t figure it out - every time I click on the screen, it displayed the cursorXPos perfectly - but when I try to use this value in “WalkToTarget,” it refuses to work ☹

private var cursorXPos:Number;  
private var cursorYPos:Number;

public function setCursorPos(mainStageMC:MovieClip)  
{

mainStageMC.onMouseDown = function()  
{  
cursorXPos = mainStageMC.\_xmouse;  
cursorYPos = mainStageMC.\_ymouse;

//this prints out the xPosition of the mouse click PERFECTLY!!!  
trace("Curstor X is = " + cursorXPos);  
trace("Curstor Y is = " + cursorYPos);

}

}

public function walkToTarget(myWorld:worldManager, mainStageMC:MovieClip)  
{  
trace(“moving agent”);

//cursorXPos always returns “undefined here no matter what!!!”  
//Even though the above function is able to properly print out the xPosition  
//this one isnt - why can’t they share!!!

trace("mouse click last X = " + cursorXPos);

myWorld.moveEntityX(“Agent West”, cursorXPos, mainStageMC);

}
