Game Development Reference
In-Depth Information
When we run the program in debug mode, the browser window comes up with a
blank view. It's blank because we are not drawing anything yet. We will need to
switch back to the Flash Builder window and notice the console view and there it
is—our string "Hello World" printed.
Now that we have test run our Hello World program, let us examine the code.
As you can see, there are 10 lines in all. Let's explore each line.
The class definition starts out with a package statement ( package { … } ) that
surrounds the rest of the file contents with the curly brackets, implying that this class
belongs to this package. Actually, the keyword package is usually followed by the
name of the package.
As this class is at root level, the package name can be left blank. However, Flash
Builder expects you to have a package name when you want to store them into
various folders in whatever fashion that suits your needs. In this case, the package
name must follow the directory structure in a dot format.
For example, you could create a folder called game at the same level as HelloWorld.
as and then specify a package name as game for all the class files that you wish to
store in that folder. If you have created a folder called util under the game folder,
then the package name for all the class files must be named game.util .
Next are the import statements:
import flash.display.Sprite;
Whenever you want to make use of a class defined elsewhere that is not in the same
folder as the class itself, you need to add an import statement for the class. In this
example, the HelloWorld class is being extended from Sprite and so we need to
import the class Sprite. Note that the import statement must include the full package
name of where it's found. As you progress through the topic, you will start to
instinctively remember what classes are in what package and what you would need
to import. The Flash Builder has a good auto-completion feature. When you type the
dot ( . ), it will offer you a list of possible completions, be they package names, class
names, properties, or method names. You can also bring up the auto-completion by
holding down the Ctrl key and pressing the space bar.
The class definition itself starts with the public class HelloWorld extends
Sprite statement. The class name itself is HelloWorld because it follows
immediately after the keyword class . It extends from a class called Sprite, which
is our friend that we will learn all about in the following chapters. The keyword
public tells the compiler that this class can be referenced from other packages.
 
Search WWH ::




Custom Search