Zombie Related Question Part II

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 :frowning:

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);

}