ActionScript originated as a simple scripting language for Macromedia Flash (supporting basic play/stop actions). It evolved into a full-fledged Object-Oriented language based on the ECMAScript standard.
Key milestones:
ActionScript 1.0 / 2.0: Prototypes and basic class declarations.
ActionScript 3.0 (AS3): Released in 2006 with Flash Player 9. AS3 was a major ground-up rewrite, introducing a high-performance virtual machine (AVM2), strict compiler typing, XML support (E4X), and a structured Event Dispatcher model.
Adobe acquired Macromedia in 2005. Following Flash Player’s deprecation in 2020, ActionScript continues to live on through the open-source Apache Flex project and HARMAN’s Adobe AIR runtime for building mobile and desktop apps.
Who:
Developed by Macromedia (later Adobe), now maintained by Apache and HARMAN.
Why:
Created to control vector animations, handle complex user interactions, process XML data feeds, and render real-time vector graphics on web browsers and standalone desktop/mobile applications.
Introduction
Advantages
Robust Event-Driven Model — Unified EventDispatcher handles touch inputs, rendering loops, and network requests cleanly.
Advanced Vector Graphics Rendering — High-performance vector drawing APIs (lines, shapes, gradients) built natively into the runtime.
E4X XML Parsing Integration — Native XML handling makes parsing, filtering, and query operations on XML feeds exceptionally simple (treating XML like regular objects).
AIR Runtime Cross-Platform — Build native desktop (macOS, Windows) and mobile (iOS, Android) applications using a single codebase.
Disadvantages
Deprecated Ecosystem — Flash Player browser plugin is no longer supported, making web distribution impossible without third-party runtimes like Ruffle.
Single-Threaded Execution — Heavy computation freezes the user interface unless broken up using asynchronous timers or worker threads.
Slow Performance for 3D — Native Vector graphics render on CPU; advanced 3D requires using Stage3D APIs, which add code complexity.
Remember Points
AVM2 Engine — AS3 runs on AVM2, which compiles code down to bytecode.
The Display List — Visual objects are only rendered on screen if they are explicitly added to the display hierarchy using addChild().
Packages and Filenames — Class names must exactly match their file names, and they must be placed in matching directory package folders.
Basics
Hello World & trace Output
package { import flash.display.Sprite; public class HelloWorld extends Sprite { public function HelloWorld() { // trace sends text output to the debugging console trace("Hello, World!"); } }}
package defines the namespace namespace folder containing this class.
// File: com/app/User.aspackage com.app { public class User { // Public properties (accessible everywhere) public var username:String; // Protected properties (accessible in class and subclasses) protected var score:int; // Private properties (accessible only inside this class) private var _password:String; // Constructor public function User(name:String, initialScore:int) { this.username = name; this.score = initialScore; } // Getter and Setter public function get password():String { return _password; } public function set password(value:String):void { if (value.length >= 6) { _password = value; } } }}
Inheritance & Interfaces
// Inherit class behavior using 'extends'public class AdminUser extends User { public function AdminUser(name:String) { super(name, 1000); // Call parent constructor } // Override methods explicitly using the 'override' keyword override public function set password(value:String):void { super.password = value + "_admin"; // call parent setter }}
Event Handling
Event Dispatcher Model
import flash.events.MouseEvent;import flash.events.Event;// 1. Add event listener (syntax: target.addEventListener(type, listener_function))myButton.addEventListener(MouseEvent.CLICK, onButtonClicked);// 2. Event Listener Callbackprivate function onButtonClicked(event:MouseEvent):void { trace("Button clicked at x: " + event.localX); // Remove event listener to prevent memory leaks when no longer needed myButton.removeEventListener(MouseEvent.CLICK, onButtonClicked);}
Custom Events
// Custom event declarationimport flash.events.Event;public class GameEvent extends Event { public static const LEVEL_UP:String = "levelUp"; public var newLevel:int; public function GameEvent(type:String, level:int, bubbles:Boolean = false, cancelable:Boolean = false) { super(type, bubbles, cancelable); this.newLevel = level; } // Overriding clone is required for custom events to work in bubble dispatching override public function clone():Event { return new GameEvent(type, newLevel, bubbles, cancelable); }}// Dispatching event:// dispatchEvent(new GameEvent(GameEvent.LEVEL_UP, 5));
// Use 5th argument of addEventListener to establish a weak reference:// addEventListener(type, listener, useCapture, priority, useWeakReference)stage.addEventListener(Event.ENTER_FRAME, onLoop, false, 0, true); // true = weak reference// When this object is removed from display, GC can clean it up automatically
Build Tools & Project Execution
Compilers
mxmlc: Adobe standard compiler for building .swf files.
adt: AIR Developer Tool for packaging apps for desktop/mobile (.exe, .dmg, .apk, .ipa).
# Compile ActionScript file to SWFmxmlc src/Main.as -o bin/Main.swf -compiler.source-path=src# Run AIR desktop debugging applicationadl src/Main-app.xml