myVar = x gives undefined :(

This is the code i’ve got, basically checks finds the x,y position of number 2 in a multidimensional array. For some reason sprite.px = x and sprite.py = y give undefined messages when i trace them. What am i doing wrong?

[AS]
for (var x = 0; x<map[x].length; x++) {
for (var y = 0; y<map.length; y++) {
if (map[y][x] == 2) {
trace(x);
trace(y);
sprite.px = x;
sprite.py = y;
trace(sprite.px);
trace(sprite.py);
}
}
}
[/AS]