Clean Up Time!!

We are making the computer do just a little bit too many calculations. It probably won't matter much for this project, but it's a good idea to get in the habit of keeping things clean.

You'll notice that every time the onEnterFrame function runs, the script has to lookup Stage.width again. Well, the stage width is something that won't change, so it makes more sense to declare it just once, as a variable:

  1. Select the beeSpeed declaration first, we want this new var to be grouped at the start of the script
  2. Click Statements > Variables > var
  3. In the Variables box type: sW = Stage.width
  4. Select the Number Data Type

Great, now that we have that variable declared right at the start of the script, we can take advantage in two separate instances. Wherever you see Stage.width, just swap it out for the variable sW:

  1. When you initially set the bee's x position
  2. When you continually check to see if the bee's x position is off the stage

Make sure your project still works, you never know unless you test it: