AS3 Tutorials Novice: Difference between revisions

The educational technology and digital learning wiki
Jump to navigation Jump to search
Line 24: Line 24:
We mentioned that ActionScript has become a serious Object Oriented language with version 3. The problem then, for a total 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.  
We mentioned that ActionScript has become a serious Object Oriented language with version 3. The problem then, for a total 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 have the expected results and they won't get away until you write your incantation correctly in all ways. 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.  
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 have the expected results and they 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.  


Any person who has followed a bit of training in magic however rapidly discovers 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 how the parts work.  
Any person who has followed a bit of training in magic however rapidly discovers 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 how the parts work.  

Revision as of 14:18, 1 November 2007

Draft

<pageby nominor="false" comments="false"/>

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. 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.

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

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.

We will attempt to give you an understanding of how things work at the next stage (Beginner).

Make sure you first run through this 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.

First words

We mentioned that ActionScript has become a serious Object Oriented language with version 3. The problem then, for a total 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 have the expected results and they 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.

Any person who has followed a bit of training in magic however rapidly discovers 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 how the parts 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 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 come back on 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. Your are likely to write programs that stand within a single package for a few weeks, so don't worry about not understanding it. We will take the time to explain this in more details, as soon as you are up to it.

Let's go exploring!

  • AS3 simple examples: introduce a small number of examples that each introduce a specific technique
  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