Shell game

Howdy, first time poster in game/ai.
I’m looking to figure out how the engine works for this shell game.
http://www.flashkit.com/movies/Games/The_Shel-Earl_Ver-10211/index.php
Just the part where the shells move around randomly (via calling frame labels).
How does the game always know where the ball is? If it’s jumping around randomly how can it keep track? I just can’t get my head around all the as.
Can anyone shed some light?