• No results found

Compiling Objects

In document UNIT 1 INTRODUCTION TO FLASH (Page 72-75)

Compiling objects is simply to give the effect on object using programming.

LetÊs see the code we're going to compile, and explain it a little.

package {import flash.display.MovieClip; import flash.text.TextField; public class HelloWorld extends MovieClip {private var text:String = "Hello world!"; public function HelloWorld()

{var textBox:TextField = new TextField(); textBox.text = text; textBox.x = 100;

textbox = 100; addChild(textBox); }}}

Firstly, as you can see, is a package declaration that we were discussing before. When using the Flex SDK (henceforth referred to as mxmlc after the binary you'll be using to compile), all classes need to be a part of a package, even if that package is anonymous.

However, you will find many people tend to name their namespaces based on their domain names, only in reverse. For example, many of my class libraries reside in a package named com.chromasplosion. When naming packages as such, the folder hierarchy the classes reside in must match the package names. Next, the package import statements: import flash.display.MovieClip; import flash.text.TextField;

These statements are what we call import statements. They tell the compiler to include the specified classes so that they are available to our class for use.

Next, we'll cover the class declaration, and cover the basics of what a class is. Public class HelloWorld extends MovieClip this line declares a new class named Hello World, which inherits from the MovieClip class. A class is an object oriented programming concept. For lack of a better explanation, a class is a kind of template that you use to create objects. Classes are used to model real world objects and even abstract concepts for use in a software model. For example, consider a house. A house may have many doors and many windows. If you were to model a house using software, you would create a single door class, and a single window class to represent these objects. You would put in the class all aspects of these objects that are common.

Considering doors, all doors have a width, height and thickness, and they all open somehow. These are attributes and methods you would model into your class. Classes tend to be unique in a software system; however you can create as many objects of a class as you want. An object that's been created from a class is often called an

"instance" of the class. OO programming when a class inherits from another class, it gets all of the inheriting classes protected and public attributes and functions. When we inherit from the Movie Class, we gain the ability to draw graphics and place objects on the Flash display stack. We won't be covering the details about the Flash display stack in this tutorial, but it may come up later.

Next, we have a variable declaration: private var text: String = "Hello world!";

The private keyword is one of 3 available keywords you can use for variables and functions: private, protected and public. A private variable or method is available only to the class it's declared in. A protected variable or method is available to the class it's been declared in, and any classes that inherit from this class. A public variable or method is available to every other class, in any package.

The var keyword declares a variable, and this variable is called "text". The colon is a type declaration, and the type is a string. We've also given it a default value of "Hello world!".

Interactive Adventure

Notes

Punjab Technical University 73 So, reading the whole line, we're declaring: a private string variable called "text" with

a default value of "Hello world!"

Then, we have a function named exactly the same as our class: public function HelloWorld ()

This is a function declaration, and because it's named the same as our class, it's what's called a constructor. A classÊs constructor is called automatically when an instance of that class is created.

Within this function, we have the following:

var textBox:TextField = new TextField();

textBox.text = text;

textBox.x = 100;

textBox.y = 100;

addChild(textBox);

Line by line:

We declare a local TextField variable named textBox, and instantiate it. This variable is visible only within this function (the constructor).

We assign the "text" parameter of "textBox" the class variable called text we defined earlier (remember, it has the value of "Hello World!").

We assign the "x" parameter of the "textBox" the value of 100. This controls it's horizontal placement on the Flash stage.

We assign the "y" parameter of the "textBox" the value of 100. This controls the vertical placement.

Then we add the textBox to the classes display list, and because this is the root class, it automatically gets placed on the stage.

Now, lets have a look at what this class creates.

If you haven't already, download the appropriate Flex SDK, and unzip it somewhere.

You don't need to install the SDK, so it doesn't matter where you unzip it.

If you're in Linux or OS X, open a terminal and if you're in Windows, open a command prompt. Navigate your way to the directory where your source file is.

Next, invoke the mxmlc compiler (Flex/bin/mxmlc) with the following:

Linux/OS X- /path/to/flex/bin/mxmlc HelloWorld.as -o HelloWorld.swf Windows: C:\Path\To\Flex\bin\mxmlc HelloWorld.as -o HelloWorld.swf

This calls the mxmlc compiler on our source file (HelloWorld.as) and specifies the swf file output (-o HelloWorld.swf).

Execute this, as you'll have compiled your first swf file on the command line.

Student Activity

Fill in the blanks:

1. The ⁄⁄⁄⁄⁄⁄⁄⁄. Animation building features a number of exhibits and interactive activities that will appeal to both kids and adults.

2. ⁄⁄⁄⁄⁄⁄⁄⁄. objects is simply to give the effect on object using programming.

3. A ⁄⁄⁄⁄⁄⁄⁄⁄. is an object oriented programming concept.

2D Animation

Notes

74 Self-Instructional Material

Summary

Interactive games present and teach at the same time Interactive games make good presentations for introducing lessons, demonstrating concepts or just to engage audiences with. Most are offered free online, and require little more than flash plug-ins. With an LCD projection device or interactive whiteboard, games can be easily presented for a number of teaching and learning purposes. The Disney Animation building features a number of exhibits and interactive activities that will appeal to both kids and adults. The Animation Academy is a 15-minute session with a Disney animator who teaches guests to draw a Disney character, such as Mickey Mouse or Pooh. Paper and pencils are provided, and guests may take their artwork home. The Art of Animation Gallery is located at the exit of the Animation Academy (it is also accessible directly from the Courtyard Gallery). Compiling objects is simply to give the effect on object using programming.

Keywords

Compiling Objects: Compiling objects is simply to give the effect on object using programming.

Text: The var keyword declares a variable, and this variable is called "text".

Colon: Colon is a type declaration, and the type is a string.

Review Questions

1. What is compiling objects?

2. What do you understand by Interactive Adventure?

Further Readings

Sandro Corsaro, Richard M Sherman, Clifford J. Parrott, Hollywood 2D Digital Animation: The New Flash Production Revolution, Cengage Learning.

Bill Davis, GardnerÊs Guide to Creating 2D Animation in a Small Studio, Garth Gardner Co.

Steve Roberts, Character Animation: 2D Skills for Better 3D, Elsevier.

Bringing Movement to the Web

Notes

Punjab Technical University 75

Unit 7 Bringing

Movement to

In document UNIT 1 INTRODUCTION TO FLASH (Page 72-75)

Related documents