Foundation Game Design with ActionScript 3.0, Second Edition

Read Foundation Game Design with ActionScript 3.0, Second Edition for Free Online

Book: Read Foundation Game Design with ActionScript 3.0, Second Edition for Free Online
Authors: Rex van der Spuy
installation directory in a folder called sdks.
    It's also important to know that Flash Builder is really just an interface for interacting with the SDK. All you really need to make Flash games is the SDK and the debug version of the Flash Player. As long as you've got those two components, you can use Flash Develop, TextMate, Eclipse, Xcode, or any other IDE to make Flash games.
    A great thing about the SDK is that if Adobe brings out a new version of the SDK with some cool new features you want to use in your game, you just need to download and install that new SDK in Flash Builder. The SDK is free, and you won't need to spend any money to upgrade to a new version of Flash Builder.
    The library is a big place, and it's divided into many different sections. Where do the sprites live? They live in a section of the library called display , and that in turn is in a bigger section of the library called flash . You can find them using these directions:
    flash.display.Sprite
    The dots between each word indicate a new section of the library. This shows that the display section is part of the flash section, and the Sprite section is part of the display section. This is like saying, “Start at the flash section, then follow the signs to the display section. In the display section you'll find the sprites.” But that's not enough. You have to tell your program to explicitly invoke the sprites using a special keyword called
import
. The
import
keyword is used to bring code out of the library so that you can use it in your program.
    Here's how to import a sprite:
    import flash.display.Sprite;
    This instructs the program to go and get a Sprite from the library in the
flash.display
section. This line of code is called an import statement . You'll be using many import statements in your AS3.0 programs and games when you want to use specialized code from the library.
    Notice that at the very end of the import statement is a semicolon (;). This is a bit of programming punctuation that means “Do what I've just told you to!” You'll see much more of the semicolon in the examples ahead.
    Also, very importantly, notice that the “S” in Sprite is capitalized. I'll explain exactly why later in the book, but for now just know that when you use the word
Sprite
in your AS3.0 programs, it must be capitalized.
    Now that you know what a Sprite is, where to find it, and the line of code that you need to write to use it in your program, go and get yourself a Sprite!
    1. Enter the following text in bold in the code editing window. Make sure that you enter it between the two curly braces.
    package
{
  import flash.display.Sprite;
}
    Notice that this new text is indented from the left margin. The code editor does this for you automatically when you add the new text. The code examples in this book use indent levels of two spaces, but the ActionScript editor window indents your code by four spaces, which is just fine.
    The indentation shows that the new code you just added is inside the package's curly braces. Very soon you'll see how important it is to indent your code like this.
    You can force the indentation of any line of code by pressing the Tab key.
    You now have the magic of AS30's Sprites at your disposal to display text and graphics!
    Your code editing window should now look like Figure 1-19 .

    Figure 1-19. Import a Sprite from the library to help you display text and images.
Don't skip class!
    Now that you've created a package and imported a Sprite, the next step is to create a class inside that package. You can think of a class as a basic building block for creating an ActionScript program.
    2. With your ActionScript editor window still open, add the following text in bold directly inside the package's curly braces:
    package
{
  import flash.display.Sprite;

  public class HelloWorld extends Sprite
  {
  }
}
    There's one blank line after the import statement and before the new code. This is optional, but as you'll see in later

Similar Books

Point of No Return

N.R. Walker

Tiger

Jeff Stone

The Perfect Soldier

Graham Hurley

Savage Coast

Muriel Rukeyser