Learning Basics of Actionscript 3

This tutorial is to get start learning basics fundamental concepts of ActionScript 3 programming, so lets start!

Object-oriented programming (OOP):  is a programming paradigm that uses objects and Classes. Data structures consisting of datafields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as information hiding, data abstraction, encapsulation, modularity, polymorphism, and inheritance.

Classes: Defines the abstract characteristics of a thing (object), in other words is a blueprint or factory that describes the nature of something. For example, the class "Car" will share characteristics will all cars, color, size, weight and different behaviors like speed.

Object: Is a pattern of a class. The class Car defines the characteristics and behaviors of a Car. The class "Mercedes" will have some specific style, color, speed, etc.

Instance: Is a blueprint of a object. The object consists of state and the behaviour that's defined in the object's class.

Methods: Actions and abilities of the object. Functions is classes are called methods.

Attributes: is the object data. Gives the state of the object

//class "Car"
public class Car {
   //private attribute, only can be accessed within the class
   private var color:String;
   //public attribute, can be accessed inside and outside of the class
   public var size:int;
       
   //Constructor of the class
   public function Car(color:String, size:int) {
      this.color = color;
      this.size = size;
   }
       
   //public method, can be accessed inside and outside of the class
   public function setColor(color:String):void{
      this.color = color;
   }
       
   //private method, only can be accessed within the class
   private function getSize():int{
      return this.size;
   }
}

//Instances of the object "Car"
car1 = new Car("blue", "200");
car2 = new Car("red", "500");

car1.setColor("yellow");

//throws an error: can't be outside of the class
car2.setSize("yellow");

0
Your rating: None

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><p>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: [code], [blockcode], [as], [as3], [css], [drupal5], [drupal6], [html], [java], [javascript], [mysql], [php], [xml].
  • You may quote other posts using [quote] tags.
  • Textual smileys will be replaced with graphical ones.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.