AS3 Tutorials Novice: Difference between revisions

The educational technology and digital learning wiki
Jump to navigation Jump to search
m (Text replacement - "<pageby nominor="false" comments="false"/>" to "<!-- <pageby nominor="false" comments="false"/> -->")
 
(47 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{stub}}


<pageby nominor="false" comments="false"/>
{{Incomplete}}


== Stage 1 : (Absolute) Novice ==
<!-- <pageby nominor="false" comments="false"/> -->


I don't know for you. I tend to learn best by doing. What gets me through complex learning is the desire to realize things. Of course, it is very important to take the time to understand complex notions thoroughly. However if you are too much worried about understanding every single aspect of the programming language before writing your first line of code, chances are high that you will give up before reaching that point. If you reach that point, the risk is that your head will be so full of unfamiliar concepts that you will completely unsure about what you should be doing next, what option to take.
== Introduction ==


Something that I find to work for me is to take a tutorial or book about the language, read it through without trying to understand everything. I do my best to understand the introductory paragraph of each chapter and to browse through the code trying to grasp the gist of how things get done. Then I go back to the beginning and start coding very simple examples. I make sure that I understand them well. I try to produce as many simple variants as I can of these simple examples. I add a new element, then a new one, etc. Once I become familiar enough with the very basic I try to come up with an idea of a little program that I could write that would make use of many of these basic elements. I write the program... I don't give up before I have finished writing it. Even if it takes me 2 or 3 days, I persevere. Once I am okay with writing an original program, I try and come up of ideas of various types of games or activities that I would like to become able to realize. I evaluate which one I can write successfully with what I already know. I evaluate what new concepts I need to master in order to write that program and the likelihood that I can get to learn these concepts in a relatively short amount of time.  I go for the most realistic options.  
This article is part of the [[Actionscript 3]] tutorial series.


In this view, what we will do next is
Make sure you also run through the section on [[AS3 Compiling a program|Compiling a program]]. You may want to print that page and keep it at hand as you will need to repeat the process for each example given in these tutorials.
# provide a simple program that is guaranteed to work (copy/paste/compile/run).
# invite you to try and write variants 
# introduce a small number of examples that each introduce a specific technique
# come up with suggestions of mini-games or activities that you could write that use these techniques
# take you through a complete example of such a mini-game.


=== Compiling a first program ===
== Stage 1 : (Absolute) Novice ==


There are potentially three ways to compile your first actionscript program:
I don't know for you. I tend to learn best by doing. What gets me through complex learning is the desire to realize things. Of course, it is very important to take the time to understand complex notions thoroughly. However if you are too much worried about understanding every single aspect of the programming language before writing your first line of code, chances are high that you will give up before reaching that point. If you reach that point, the risk is that your head will be so full of unfamiliar concepts that you will completely unsure about what you should be doing next, what option to take.  
# Compiling with the Flash CS3 Authoring tool
# Compiling with Flex Builder
# Compiling with the binary mxmlc included in the Flex framework.  


Here, we will describe how to compile with mxmlc. This assumes that your Flex framework is properly installed. For information on how to install it on the [[Adobe Flex]] page.
Something that I find to work for me is to take a tutorial or book about the language, read it through without trying to understand everything. I do my best to understand the introductory paragraph of each chapter and to browse through the code trying to grasp the gist of how things get done. That's absolute novice stage.  
 
Open a text editor, a simple one that will save the text as it appears on the screen, without any formatting. In that new text file, copy the following code:
 
  package  {
    import flash.display.Sprite;
    public class FilledCircle extends Sprite {
        function FilledCircle():void {
          var circle:Sprite = new Sprite();
          circle.graphics.beginFill(0xFF794B);
          circle.graphics.drawCircle(50, 50, 30);
          circle.graphics.endFill();
          addChild(circle);
        }
    }
  }


Save the file as text and give it the name of "FilledCircle.as".  Take good note of the directory in which you save that file. Preferably, put it in a folder quite high up in the hierarchy. We will assume that the file is stored somewhere defined by "\path\to\file\".
I would wait for Beginner stage to read each chapter in details. I will read chapters one by one and not move to the next chapter until I feel that I understand all concepts well enough. I will also take the time to hand code (rather than copy and paste) the simple examples proposed in that chapter. I will start to explore and attempt to write variants of these simple examples, adding a new element each time or trying to merge two examples together to produce a more complex result. I will then move to the next chapter. If I chapter is too difficult or the content of limited interest, I go through it rapidly and move on.


==== On a mac ====
Then Intermediate stage. Once I become familiar enough with the basics I try to come up with an idea of a little program that I could write that would make use of many of these basic elements. I attempt write the program... I don't give up before I have finished writing it. I don't read the book sequentially anymore. I mostly use the index at the back of the book to try and locate the information I need to solve the problems that I set to myself. Once I am okay with writing an original program, I try and come up of ideas of various types of games, learning activities or mini-apps that I would like to become able to realize. I evaluate which one I can write successfully with what I already know. I evaluate what new concepts I need to master and the likelihood that I can get to learn these concepts in a short enough amount of time.  I go for the most realistic options.


# Open a terminal window. Terminal is an application like any other. To find it, go to the Applications -> Utilities. You should see Terminal.app among the files.  
For now, we are at novice stage. The priority here is to develop your familiarity with actionscript code. You are not expected to be able to write a program from scratch, only to give a try at modifying a few values or slightly reorganizing a few lines of code. In this view, what we will do next is :
# Double click on the application to open it.
# provide a simple program that is guaranteed to work (copy/paste/compile/run).
# At the prompt, type:
# invite you to try and write variants 
# introduce a small number of examples that each introduce a specific technique


  cd \path\to\file\
Then we will move onto Beginner level and give you an understanding of how things work as well as provide you with the minimal skills you need to write your own code.
  mxmlc FilledCircle.as


==== On a PC ====   
=== First words ===


# From the Windows start menu, open a command prompt by choosing Start > All Programs > Accessories > Command Prompt.  
We mentioned that ActionScript has become a serious Object Oriented language with version 3. The problem then, for an absolute newbie, is that the use of Object Oriented constructs are not optional. They are mandatory. The consequence of this is that any ActionScript programs contains elements that are somehow puzzling for the person who only started programming. Don't worry about this.  
# At the command prompt, change to the C:\Flex SDK 2\bin directory then execute the mxmlc executable on your actionscript file.  


  cd C:\Flex SDK 2\bin
For now, at this complete novice stage, consider them as magical incantations. In the age of Harry Potter or Eragon, we all know that magical incantations need to be precisely reproduced, each bit must be correctly spelt. Otherwise you have the risk of unwelcome results. In a programming set up, the awkward results are called errors. They pop on the screen to tell you that your program didn't work and these error messages won't get away until you incantation is correct in every way. Sometimes they let your program run but with completely unexpected results. You wanted a rabbit to pop out of your hat and you got a snake instead! Yuk! Sometimes they prevent your program from running altogether. That's the major difficulty when learning a serious programming language. You need to get these incantations correct or your program won't run.  
  mxmlc C:\path\to\file\FilledCircle.as


The mxmlc executable will compile the program and generate a .swf file name FilledCircle.swf. To run the file, open it in the Flash Player on your desktop or in a web browser that has Flash Player installed. Note that Flash Player 9 needs to be installed to view swf files generated by the Flex compiler.
Any person who has followed a bit of training in magic however knows that magical incantations are not in fact unbreakable constructs. They are made of parts that can be combined in different ways to give various results. It goes the same with programming. As soon as beginner stage, we will start to explain what the parts are and how they work.  


For now, what matters is to get you started. It's a bit like arriving in a new city, for example to go to University. The first week is spent wandering around to try and locate the grocerer, the bank, the post office and other facilities. At Novice level, we will invite you to do exactly this. Wander about, get some kind of global mental map of the new environment you will get to live in for the next few months and perhaps the next few years.


=== How does it work? ===
If you were to go to live to London, Australia, or Japan, you would need to get used to driving on the left side of the road. When you program in ActionScript 3, what you have to get used to is declaring classes and packages, as explained below. Like riding on the left side of the road, this sounds *very* weird and *completely* unnatural at first. You will progressively get used to it, though.


Okay, let's go through that program step by step to try and understand how this works.
==== Everything needs to be organized into classes ====


----
In ActionScript 3 *Everything* needs to be organized into classes. You must have at least one class in your program. This can appear quite obscure at first. But because the class definition always uses the same format, that's simply a question of getting used to add these extra lines in your code. Initially you will write short programs that don't justify the use of more than a single class. Don't worry if you don't understand that class concept yet. What matters is that you start going, start writing a bit of code and become able to play around. We will explain the concept of class soon enough.  
  package {


No string follow the word package. This means that we don't bother storing our code in independent regions. We have a single package.
// The class definition
public class Game {
    // instance variable of type integer
    var score:int
   
   
----
  // The constructor method
     import flash.display.Sprite;
     public function Game () {
          // code that initialize Game instances
    }
   
  // instance method
    public function updateScore ():void {
        // code to execute when updateScore () is invoked
    }
}


The import statement is a consequence of the class organisation. Though we won't make use of classes in our very first programs, the thing is that the code that defines how Flash works and how elements are layed out on the screen is defined within a class-based organization. Each class does something very specific. There is one, for instance that contains all the code required for drawing graphics on the screen. This class is the Sprite class. And the Sprite class belongs to the display package which is itself part of the flash package.
==== Classes need to be placed in a package ====


Greatly simplified, what this means is ... we will need to play with Sprite objects (that is objects that can be drawn into) in this program, so please make all the code associated to Sprite objects available to my program.  
With the class-based organisation comes another concept, the one of package. A package is a conceptual container. It is used to group classes that operate together within a physical region of their own. Its main function is to help organize the code for large applications. The recommendation here is the same as for classes. In a first time, simply use the syntax without worrying too much about not understanding what it is for.  


----
For a few days or weeks, you are likely to write programs that stand within a single package. All you need to know, therefore, is that for a program to run, you must enclose each class in a package. You can provide a pathname to point to a given region in your codespace. If you don't need different regions, you can simply use the package declaration on its own.
    public class FilledCircle extends Sprite {


This is a class definition. This corresponds to saying what follows is the code that defines FilledCircle objects and their behaviors. The extends part means that we want our FilledCircle object to inherit all properties of a Sprite object (more about this later).
package {
   
   
----
  // The class definition
        function FilledCircle():void {
  public class Game {
 
    // instance variable of type integer
This is an instance constructor. When any part of the program tries to create an object of type FilledCircle, run this code. The best way to conceptualize this is initialization code every time a new object is being created.
      var score:int
   
   
----
      // The constructor method
          var circle:Sprite = new Sprite();
      public function Game () {
            // code that initialize Game instances
      }
   
      // instance method
      public function updateScore ():void {
          // code to execute when updateScore () is invoked
      }
    }
}


What we do here is declare a variable called circle and have it hold the definition of a new Sprite Object. The reason we need to create one is because we want to draw something on the screen. We could draw directly on the screen.. But then we would loose any ability to manipulate the object later on. See it like the contrast between creating graphics on a blackboard and creating graphics with a sophisticated enough image editing software. If you draw a circle on a blackboard, then late on add some text, you might discover that you don't have room enough and you need to move the circle. On a blackboard, you can't. You have to restart from scratch. Erase a part or the totality of the content of the board and start drawing again. When you use an image editing software, if you come to discover that the circle was not drawn at the right location, you can select it and move it somewhere else on the screen without having to redraw it.
=== Requirements  ===


Well, that's what Sprites are about. They define a small display area able to contain graphics and media content that you can reposition or manipulate later on.  
Make sure you first run through the section on [[AS3 Compiling a program|Compiling a program]]. You may want to print that page and keep it at hand as you will need to repeat the process for each example given in these tutorials.


We mentioned that AS3 is a strongly typed object. Because of that we have to write ''var circle:Sprite = new Sprite()'' rather than ''var circle = new Sprite()''. We create a variable called circle and we specify to the program that the type of information that this variable will hold is the definition of a Sprite object.
=== Tips  ===


----
Don't forget that there is a list of [[AS3 Useful links]] you can consult at any point.
          circle.graphics.beginFill(0xFF794B);
          circle.graphics.drawCircle(50, 50, 30);
          circle.graphics.endFill();


This part draws a circle. It doesn't draw a circle directly on the screen. What it does is to draw a circle within a Sprite object. Because of that, each line starts with circle, the sprite object in which we want the graphics to be added. Then we grab the drawable area ("graphics") and we perform various drawing actions on it. '''beginFill''' specifies that we want to draw filled shapes. What follows is a color parameter. The value of "0xFF794B" is at first sight a bit strange. It defines a color in a format easy to manipulate for a computer. This is exactly the same hexadecimal format than used in HTML in case you are already familiar with it (0xFFFFFF stands for white, 0x000000 stands for black). Let's not spend too much time on this. Color code values can be obtained on this [http://www.webmonkey.com/reference/color_codes/ color code reference page] at webmonkey.com. '''drawCircle''' draws a circle which has for center the point (50,50) (50 pixels from the left, 50 pixels from the top) and for radius 30 (30 pixels). '''endFill''' indicates that we have finished with drawing filled shapes.
=== Let's go exploring! ===


----
* [[AS3 simple examples]]: introduce a small number of examples that each introduce a specific technique. You should follow these example tutorials in the same order.
          addChild(circle);
# [[AS3 example Drawing graphics]]
 
# [[AS3 example Message Box]], mixing graphics and text on the screen
Above we mentioned that we didn't draw directly on the screen. What we did was to draw onto a Sprite object. For the circle to appear on the screen, it is necessary to add the sprite object to the stage.
# [[AS3 example Button]]
# [[AS3 example Positioning]]
----
# [[AS3 example Drag and Drop]]
        }
# [[AS3 example Keyboard control]]
    }
# [http://everythingfla.com/course/basics/start-point Video: Learn The Basics of setting up a project in AS3/Flash ]
  }
 
Any parenthesis or bracket that has been opened must be closed.
 
=== Variants ===
 
Try and change the position of the circle and its size. Change the color. Try to draw a [http://images.google.com/images?svnum=10&um=1&hl=en&safe=off&client=safari&rls=en&q=bulleye&btnG=Search+Images bulleye].
 
Why not draw other shapes?
 
For a rectangle, use
 
sprite.graphics.drawRect(x, y, width, height);
 
For an ellipse, use
 
sprite.graphics.drawEllipse(x, y, width, height);
 
For a rounded rectangle, use:  
 
sprite.graphics.drawRoundRect(x, y, width, height, ellipseWidth, ellipseHeight);
 
=== Gotchas ===
 
When you tried to create multiple shapes, did it work? If yes, congratulations! I am really impressed.
 
If not, what is the error that appeared in your terminal window? I would bet that you got "Warning: Duplicate variable definition". What does it mean? How to fix it?
 
There is only one variable in the short program we have provided. If you don't remember what it is, run a search on "variable" on this web page. When pressing next to go through all matching strings, you should at some point end up on this sentence "What we do here is declare a variable called circle and have it hold the definition of a new Sprite Object."
 
This is correct, we declared a variable called circle. An issue with object oriented languages is that variables need to be declared the very first time they are being used. This is the ''var'' part of the line. This means we define something called "circle" that from now on we will use as a variable. You have to declare a variable the very first time you use it. You cannot declare a variable more than once.
 
If you tried to copy and paste the code multiple times to create multiple shapes, chances are that you did this:
 
          var circle:Sprite = new Sprite();
          circle.graphics.beginFill(0xFF794B);
          circle.graphics.drawCircle(50, 50, 30);
          circle.graphics.endFill();
          addChild(circle);
          var circle:Sprite = new Sprite();
          circle.graphics.beginFill(0xFF794B);
          circle.graphics.drawCircle(50, 50, 30);
          circle.graphics.endFill();
          addChild(circle);
 
That doesn't work because twice you get to create a brand new variable that as for name "circle". What you need to do is use a different name each time you create a new variable.
 
This will work:
 
          var circle1:Sprite = new Sprite();
          circle1.graphics.beginFill(0xFF794B);
          circle1.graphics.drawCircle(50, 50, 30);
          circle1.graphics.endFill();
          addChild(circle1);
          var circle2:Sprite = new Sprite();
          circle2.graphics.beginFill(0x0083D7);
          circle2.graphics.drawCircle(50, 50, 15);
          circle2.graphics.endFill();
          addChild(circle2);
 
 
Something else will work. Can you guess? Do we necessarily need to define different drawing objects for circles, rectangles, etc. Can we not draw different shapes in the same sprite? Have a try.  
 
          var s:Sprite = new Sprite();
          s.graphics.beginFill(0xFF794B);
          s.graphics.drawCircle(50, 50, 30);
          s.graphics.endFill();
          s.graphics.beginFill(0x0083D7);
          s.graphics.drawCircle(50, 50, 15);
          s.graphics.endFill();
          addChild(s);
 
=== Challenge ===
 
Can you draw a house, with roof, chimney, window, door?
 
If not, what are you missing? What about the roof? How to draw a triangular roof? How to find the information you need to draw a triangle? If you go to google.com and run a search on [http://images.google.com/images?svnum=10&um=1&hl=en&safe=off&client=safari&rls=en&q=%22actionscript+3%22+triangle&btnG=Search+Images "actionscript 3" triangle], do you find any page that help find out how to draw a triangle?
 
Btw, how to draw a simple line? This could come in handy. After all, a triangle is a shape made of three lines.
 
If you had no success with Google, try the [http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000178.html adobe live documentation]. Can you draw a simple line or a triangle now?
 
=== Clarifications===
 
But, but, if I was to use Flash CS3, I wouldn't have to bother about all that package and class definition stuff. Yes and No. If you were to type your code directly within your authoring environement, this is correct, you wouldn't have to bother with these extra lines. If you were to rely on an external .as file like we demonstrated here, you should have to do so.
 
Have a try, use the following program
 
  import flash.display.Sprite;
  var circle:Sprite = new Sprite();
  circle.graphics.beginFill(0xFF794B);
  circle.graphics.drawCircle(50, 50, 30);
  circle.graphics.endFill();
  addChild(circle);
 
And try to compile it with the method we described above. You will get the following error message: "file found in a source-path must have an externally visible definition. If a definition in the file is meant to be externally visible, please put the definition in a package."
 
Try adding the package definition:
 
  package {
    import flash.display.Sprite;
    var circle:Sprite = new Sprite();
    circle.graphics.beginFill(0xFF794B);
    circle.graphics.drawCircle(50, 50, 30);
    circle.graphics.endFill();
    addChild(circle);
  }
 
You will get this error: "A file found in a source-path can not have more than one externally visible definition. circle;rect".
 
In other words, you '''must''' use the package and class definition constructs whenever you code is in ".as" files. What we have given above  as the correct file to run
 
package  {
  import flash.display.Sprite;
  public class FilledCircle extends Sprite {
      function FilledCircle():void {
        var circle:Sprite = new Sprite();
        circle.graphics.beginFill(0xFF794B);
        circle.graphics.drawCircle(50, 50, 30);
        circle.graphics.endFill();
        addChild(circle);
      }
    }
}
 
is really the minimal file you can write.  No worries, that's simply a matter of getting used to add that ''package'' line and ''public class'' line at the top of any ".as" file.
 
=== Let's go exploring! ===


We have covered step 1 and 2. What remains is to go through step 3 to 5.
Enjoy !


* [[AS3 simple examples]]: introduce a small number of examples that each introduce a specific technique


[[Category: Technologies]]
[[Category: Multimedia]]
[[Category: Multimedia]]
[[Category: Actionscript 3]]
[[Category: Actionscript 3]]
[[Category: Flash]]
[[Category: Flash]]
[[Category: Flex]]
[[Category: Flex]]
[[Category:ActionScript tutorials]]

Latest revision as of 18:21, 22 August 2016


Introduction

This article is part of the Actionscript 3 tutorial series.

Make sure you also run through the section on Compiling a program. You may want to print that page and keep it at hand as you will need to repeat the process for each example given in these tutorials.

Stage 1 : (Absolute) Novice

I don't know for you. I tend to learn best by doing. What gets me through complex learning is the desire to realize things. Of course, it is very important to take the time to understand complex notions thoroughly. However if you are too much worried about understanding every single aspect of the programming language before writing your first line of code, chances are high that you will give up before reaching that point. If you reach that point, the risk is that your head will be so full of unfamiliar concepts that you will completely unsure about what you should be doing next, what option to take.

Something that I find to work for me is to take a tutorial or book about the language, read it through without trying to understand everything. I do my best to understand the introductory paragraph of each chapter and to browse through the code trying to grasp the gist of how things get done. That's absolute novice stage.

I would wait for Beginner stage to read each chapter in details. I will read chapters one by one and not move to the next chapter until I feel that I understand all concepts well enough. I will also take the time to hand code (rather than copy and paste) the simple examples proposed in that chapter. I will start to explore and attempt to write variants of these simple examples, adding a new element each time or trying to merge two examples together to produce a more complex result. I will then move to the next chapter. If I chapter is too difficult or the content of limited interest, I go through it rapidly and move on.

Then Intermediate stage. Once I become familiar enough with the basics I try to come up with an idea of a little program that I could write that would make use of many of these basic elements. I attempt write the program... I don't give up before I have finished writing it. I don't read the book sequentially anymore. I mostly use the index at the back of the book to try and locate the information I need to solve the problems that I set to myself. Once I am okay with writing an original program, I try and come up of ideas of various types of games, learning activities or mini-apps that I would like to become able to realize. I evaluate which one I can write successfully with what I already know. I evaluate what new concepts I need to master and the likelihood that I can get to learn these concepts in a short enough amount of time. I go for the most realistic options.

For now, we are at novice stage. The priority here is to develop your familiarity with actionscript code. You are not expected to be able to write a program from scratch, only to give a try at modifying a few values or slightly reorganizing a few lines of code. In this view, what we will do next is :

  1. provide a simple program that is guaranteed to work (copy/paste/compile/run).
  2. invite you to try and write variants
  3. introduce a small number of examples that each introduce a specific technique

Then we will move onto Beginner level and give you an understanding of how things work as well as provide you with the minimal skills you need to write your own code.

First words

We mentioned that ActionScript has become a serious Object Oriented language with version 3. The problem then, for an absolute newbie, is that the use of Object Oriented constructs are not optional. They are mandatory. The consequence of this is that any ActionScript programs contains elements that are somehow puzzling for the person who only started programming. Don't worry about this.

For now, at this complete novice stage, consider them as magical incantations. In the age of Harry Potter or Eragon, we all know that magical incantations need to be precisely reproduced, each bit must be correctly spelt. Otherwise you have the risk of unwelcome results. In a programming set up, the awkward results are called errors. They pop on the screen to tell you that your program didn't work and these error messages won't get away until you incantation is correct in every way. Sometimes they let your program run but with completely unexpected results. You wanted a rabbit to pop out of your hat and you got a snake instead! Yuk! Sometimes they prevent your program from running altogether. That's the major difficulty when learning a serious programming language. You need to get these incantations correct or your program won't run.

Any person who has followed a bit of training in magic however knows that magical incantations are not in fact unbreakable constructs. They are made of parts that can be combined in different ways to give various results. It goes the same with programming. As soon as beginner stage, we will start to explain what the parts are and how they work.

For now, what matters is to get you started. It's a bit like arriving in a new city, for example to go to University. The first week is spent wandering around to try and locate the grocerer, the bank, the post office and other facilities. At Novice level, we will invite you to do exactly this. Wander about, get some kind of global mental map of the new environment you will get to live in for the next few months and perhaps the next few years.

If you were to go to live to London, Australia, or Japan, you would need to get used to driving on the left side of the road. When you program in ActionScript 3, what you have to get used to is declaring classes and packages, as explained below. Like riding on the left side of the road, this sounds *very* weird and *completely* unnatural at first. You will progressively get used to it, though.

Everything needs to be organized into classes

In ActionScript 3 *Everything* needs to be organized into classes. You must have at least one class in your program. This can appear quite obscure at first. But because the class definition always uses the same format, that's simply a question of getting used to add these extra lines in your code. Initially you will write short programs that don't justify the use of more than a single class. Don't worry if you don't understand that class concept yet. What matters is that you start going, start writing a bit of code and become able to play around. We will explain the concept of class soon enough.

// The class definition
public class Game {
   // instance variable of type integer
   var score:int

  // The constructor method
   public function Game () {
         // code that initialize Game instances
   }
   
  // instance method
   public function updateScore ():void {
       // code to execute when updateScore () is invoked
   }
}

Classes need to be placed in a package

With the class-based organisation comes another concept, the one of package. A package is a conceptual container. It is used to group classes that operate together within a physical region of their own. Its main function is to help organize the code for large applications. The recommendation here is the same as for classes. In a first time, simply use the syntax without worrying too much about not understanding what it is for.

For a few days or weeks, you are likely to write programs that stand within a single package. All you need to know, therefore, is that for a program to run, you must enclose each class in a package. You can provide a pathname to point to a given region in your codespace. If you don't need different regions, you can simply use the package declaration on its own.

package {

  // The class definition
  public class Game {
    // instance variable of type integer
     var score:int

     // The constructor method
      public function Game () {
            // code that initialize Game instances
      }
    
     // instance method
      public function updateScore ():void {
          // code to execute when updateScore () is invoked
      }
   }
}

Requirements

Make sure you first run through the section on Compiling a program. You may want to print that page and keep it at hand as you will need to repeat the process for each example given in these tutorials.

Tips

Don't forget that there is a list of AS3 Useful links you can consult at any point.

Let's go exploring!

  • AS3 simple examples: introduce a small number of examples that each introduce a specific technique. You should follow these example tutorials in the same order.
  1. AS3 example Drawing graphics
  2. AS3 example Message Box, mixing graphics and text on the screen
  3. AS3 example Button
  4. AS3 example Positioning
  5. AS3 example Drag and Drop
  6. AS3 example Keyboard control
  7. Video: Learn The Basics of setting up a project in AS3/Flash

Enjoy !