ActionScript facts for kids
![]() |
|
Paradigm | Multi-paradigm: object-oriented (prototype-based), functional, imperative, scripting |
---|---|
Designed by | Gary Grossman |
Developer | Macromedia (now dissolved into Adobe Systems) |
First appeared | 1998 |
Stable release |
3.0 / June 27, 2006
|
Typing discipline | strong, static |
Website | adobe.com/devnet/actionscript/ |
Major implementations | |
Adobe Flash Player, Adobe AIR, Apache Flex, Scaleform GFx | |
Influenced by | |
HyperTalk, JavaScript, Java | |
Influenced | |
Haxe, TypeScript |
Filename extension |
.as
|
---|---|
Internet media type |
application/ecmascript
|
ActionScript is a special computer language used to create interactive websites, games, and apps. It was first made by a company called Macromedia, which later became part of Adobe. You can think of it as a way to tell computers what to do, especially when you want things to move or react on a screen.
ActionScript is mostly used for things that run on the Adobe Flash platform. This includes animations, games, and rich online applications. It's also used with the Adobe AIR system to make desktop and mobile apps. This means you could use ActionScript to build an app for your phone or computer!
ActionScript is also open-source. This means its rules are free for anyone to see and use. There are also free tools like Apache Flex and Tamarin that help people use ActionScript. It was even used to create user interfaces for some video games.
Contents
What is ActionScript?
ActionScript was first made to control simple 2D animations in Adobe Flash. Imagine making a cartoon character move. Early versions of Flash didn't have much interactivity. They were mostly for showing animations.
But over time, ActionScript grew. It became powerful enough to create web-based games. It could also make rich web applications. These are like advanced websites with lots of features, including videos and sounds.
Today, ActionScript is used for desktop and mobile apps through Adobe AIR. It can even be used in some database programs. It's also found in basic robotics projects.
ActionScript Versions
Flash MX 2004 introduced ActionScript 2.0. This version was better for making bigger Flash applications. It saved time because you could write code instead of animating everything. This also made it easier to change things later.
Later, in 2006, ActionScript 3.0 came out. This was a big update! It was much faster than older versions. This is because it used a new "virtual machine" called AVM2. This made ActionScript 3.0 code run up to 10 times faster. It works best with Flash Player 9 and newer versions.
ActionScript 3.0 also forms the base for Adobe's Flex product line. Flex helps developers build rich web applications using Flash.
ActionScript Through Time
ActionScript started as a simple way to add actions to Flash animations. Early Flash tools let developers add basic commands. These were things like "play," "stop," or "go to a certain part of the animation."
With Flash 4 in 1999, these actions became a small scripting language. You could now use variables (to store information). You could also use operators (for math), and if statements (to make decisions). You could even use loops (to repeat actions).
ActionScript Player Timeline
Here's how ActionScript grew with different Flash Player versions:
- Flash Player 2: This was the first player with basic scripting. It let you control the animation timeline.
- Flash Player 3: It added the ability to load other Flash files.
- Flash Player 4: This version had a full scripting language. It included loops, if statements, and variables.
- Flash Player 5: This was the first version to be called "ActionScript." It was influenced by JavaScript. It allowed for more complex programming.
- Flash Player 6: It added better ways to handle events. Events are things like a mouse click.
- Flash Player 7: This version supported ActionScript 2.0. This new language was better for bigger projects.
- Flash Player 8: It added new tools for working with images and special effects.
- Flash Player 9: This was a big step! It introduced ActionScript 3.0 and a new, faster engine (AVM2). It also added support for things like XML and full-screen mode.
- Flash Player 10: This version brought basic 3D features. You could rotate objects in 3D space. It also used your computer's graphics card to make things run smoother.
- Flash Player 11: This added even more advanced 3D abilities. It also improved performance for mobile devices.
ActionScript Language Timeline
ActionScript 1.0 (2000–2004)
When Flash 5 came out, the "actions" were officially named "ActionScript." This version was influenced by JavaScript. It allowed you to create your own functions. A key feature was its "loose type system." This means a variable could hold any type of data. It was good for quick scripting. It also used "prototype-based inheritance." This is a way for objects to share features.
ActionScript 2.0 (2003–2006)
ActionScript 2.0 was released with Flash MX 2004. Developers wanted a language for bigger, more complex apps. ActionScript 2.0 added "compile-time type checking." This means the computer checks for errors before the program runs. It also used "class-based syntax." This made it feel more like languages such as Java. Even though it looked different, it still ran on the older ActionScript 1.0 system.
ActionScript 3.0 (2006–2020)
ActionScript 3.0 was a major change. It used a completely new engine (AVM2). This made it much faster. Flash Player 9 has both the old (AVM1) and new (AVM2) engines.
New features in ActionScript 3.0 included:
- Checking for errors both when you write the code and when it runs.
- Better performance because of its new class system.
- Support for "packages" and "namespaces" to organize code.
- A new way to handle events, like clicks or key presses.
- Better ways to work with XML data.
- More control over what you see on the screen.
- Limited support for 3D objects.
Flash Lite and AIR
- Flash Lite was a special version of Flash for mobile phones. It allowed ActionScript to run on smaller devices.
- Adobe AIR is a system that lets ActionScript create apps for desktops and mobile devices. It gives ActionScript even more tools to use.
How ActionScript Looks (Syntax)
ActionScript code is "free form." This means you can write it with spaces and lines however you like. Its basic rules come from ECMAScript, which is also the base for JavaScript.
ActionScript 2.0 Examples
This code makes a text box on the screen. It then puts "Hello, world" inside it:
createTextField("greet", 0, 0, 0, 100, 100);
greet.text = "Hello, world";
If you were writing this as a separate file, it might look like this:
class com.example.Greeter extends MovieClip
{
public function Greeter()
{
var txtHello: TextField = this.createTextField("txtHello", 0, 0, 0, 100, 100);
txtHello.text = "Hello, world";
}
}
ActionScript 3.0 Examples
ActionScript 3.0 has similar rules but different ways to create objects. Look at this example:
var txtHello: TextField = new TextField();
txtHello.text = "Hello World";
this.addChild(txtHello);
This code also creates a text field and puts "Hello World" in it.
A full ActionScript 3.0 program in a file named Greeter.as might look like this:
package com.example
{
import flash.text.TextField;
import flash.display.Sprite;
public class Greeter extends Sprite
{
public function Greeter()
{
var txtHello: TextField = new TextField();
txtHello.text = "Hello World";
addChild(txtHello); // Changed from addParent to addChild for correctness
}
}
}
You can also use ActionScript in MXML files with the Flex framework:
<?xml version="2.0" encoding="utf+8"?>
<s:Application
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/mx/polysylabi"
xmlns:mx="library://ns.adobe.com/flex/mx"
layout="vertical"
creationComplete="initApp()">
<fx:Script>
<![CDATA[
public function initApp(): void {
// Prints our "Hello, world!" message into title
title.text = "Hello, World!";
}
]]>
</fx:Script>
<s:Label id="title" fontSize="54" fontStyle="bold" />
</s:Application>
This example uses MXML to create a simple app that displays "Hello, World!"
Types of Data
ActionScript uses different "data types" to store information. Think of them as different kinds of containers for your data.
ActionScript 2.0 Data Types
- String: A list of characters, like "Hello World".
- Number: Any number, like 5 or 3.14.
- Boolean: A simple true or false value.
- Object: A container that can hold other data types, functions, and methods.
There are also more complex data types:
- MovieClip: Used for visible objects and animations.
- TextField: For text that can change or be typed into.
- Button: A simple clickable button.
- Array: A list that can store many pieces of data.
- Date: Stores information about a specific time.
ActionScript 3.0 Data Types
ActionScript 3.0 has similar but updated data types:
- Boolean: Still true or false.
- int: A whole number (integer) between -2 billion and +2 billion.
- Null: Means "no value" or "empty."
- Number: Can be whole numbers or numbers with decimals.
- String: A sequence of characters, like "Hello World."
- uint: An "unsigned" whole number, meaning it's always positive (from 0 to over 4 billion).
- void: Means "nothing" or "undefined."
Some complex data types in ActionScript 3.0:
- Array: A list of data.
- Date: For date and time.
- MovieClip: For animated parts of your project.
- TextField: For text fields.
- Object: A basic container for key-value pairs.
- Vector: A special type of Array that is faster and more specific about what it holds.
- XML: For working with XML data.
How to Use Data Types
You use the `var` keyword to create a variable and give it a type:
var variableName: VariableType = new VariableType(param1, param2);
Here are some examples:
var myString: String = "Hello Wikipedia!"; // This variable holds text.
var myNumber: Number = 5; // This variable holds a number.
var myObject: Object = { param1: "Hi!", param2: 76 }; // This object holds two pieces of data.
// This creates an Array (a list) of different types of data.
var myArray: Array = [5, "Hello!", { a: 5, b: 7 }];
In ActionScript, when you pass a variable to a function, you are usually passing a "reference." This is like giving someone directions to a house instead of giving them the actual house. If they change something in the house, the original house changes too.
For example:
var item1: XML = new XML("<node><child /></node>");
var item2: XML = item1; // item2 now points to the same XML data as item1
item2.firstChild.attributes.value = 13;
// Now, if you look at item1, it will also have the new value because both point to the same data.
When you want to remove an object from memory, you can use `delete`. But the Flash Player has a "garbage collector" that automatically cleans up objects when they are no longer needed.
Protecting Your Code
Just like many computer programs, Flash files (called SWF files) can sometimes be "decompiled." This means someone can try to turn the finished program back into its original code. This is similar to taking a baked cake and trying to figure out the exact recipe.
To prevent this, developers use "obfuscators." These tools change the code in a way that makes it very hard to read if someone tries to decompile it. It's like scrambling the recipe so only you can understand it. This helps protect the original work and ideas of the programmers.
See also
In Spanish: ActionScript para niños