It shouldn't be the problem, but may don't declare "int" but "var", i don't know if the engine makes differences when working with window(). The rest of the code seams to be ok, I can't see any mistake by looking at it.

Regards
TSGames