You should shift all the checks in onenter
upwards, prior to assigning anything to either sheep or other objects. Then you will likely find that one of the objects is null. The #1009 error means that some object reference that's placed right before a "." qualifier is null, and you can't get properties out of nothing.
Also, try placing return
right after any call of nextFrame()
, because when you perform nextframe, the previous frame's vars are invalidated, thus you can't refer to say hand
because there's no more hand, it's destroyed along with the whole previous frame.