Data Types

This is going great for now, partly because we are working on such a simple project. If you wanted to double the bee's velocity, you just change the value to bee._x+10; If you wanted the bee to move "backwards," you just change the value to bee._x-5;

It's going to make much more sense to change that number into a variable. That way if you keep building and building on this code, then you want to experiment with the bee's speed, you won't have to go hunting around for the code that makes that happen. So why not just create a variable called beeSpeed and set it at the very start of the script?

From now on, we're using set variable to set properties, and we'll use We're going to start setting variables using a new method: var

A benefit of using var is that it allows you to set data types. There are many different data types, and they generally help you to detect errors in your code by restricting the variable to only one type of data (such as numbers, or text):

  1. Select the closing brace } for the onEnterFrame function. You want to set this variable outside the function, so it happens only one time.
  2. Click Statements > Variables > var
  3. Enter the Variable beeSpeed = 5
  4. Select the Number data type

Now change the Value in the set variable statement to bee._x+beeSpeed:

Finally, move the beeSpeed variable declaration to the very start of the script. This is a great organizing method. If you return to this project in a few months, you won't want to waste a ton of time figuring out how you got the bee to move, or where you set the variable. It will be easy to open the project and quickly locate the speed without having to hunt through a ton of code:

  1. Select the var actions you want to move
  2. Click the Move Selected Actions Up button until the actions move to the very top

Test your work to make sure your bee is still buzzing right off the screen!