AS3 Tutorials Novice

The educational technology and digital learning wiki
Jump to navigation Jump to search


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 !