Gunjan’s Weblog

Share your knowledge in Flash and Flex

Actionscript versions January 15, 2008

ActionScript version

2000–2003: ActionScript “1.0″ With the release of Flash 5 in September 2000, the “actions” from Flash 4 were enhanced once more and named “ActionScript” for the first time.[2] This was the first version of ActionScript with influences from JavaScript and the ECMA-262 (Third Edition) standard, supporting the said standard’s object model and many of its core data types. Local variables may be declared with the var statement, and user-defined functions with parameter passing and return values can also be created. Notably, ActionScript could now also be typed with a text editor rather than being assembled by choosing actions from drop-down lists and dialog box controls. With the next release of its authoring tool, Flash MX, and its corresponding player, Flash Player 6, the language remained essentially unchanged; there were only minor changes, such as the addition of the switch statement and the “strict equality” (===) operator, which brought it closer to being ECMA-262-compliant. Two important features of ActionScript that distinguish it from later versions are its loose type system and its reliance on prototype-based inheritance. Loose typing refers to the ability of a variable to hold any type of data. This allows for rapid script development and is particularly well-suited for small-scale scripting projects. Prototype-based inheritance is the ActionScript 1.0 mechanism for code reuse and object-oriented programming. Instead of a class keyword that defines common characteristics of a class, ActionScript 1.0 uses a special object that serves as a “prototype” for a class of objects. All common characteristics of a class are defined in the class’s prototype object and every instance of that class contains a link to that prototype object.

2003–2006: ActionScript 2.0 The next major revision of the language, ActionScript 2.0, was introduced in September 2003 with the release of Flash MX 2004 and its corresponding player, Flash Player 7. In response to user demand for a language better equipped for larger and more complex applications, ActionScript 2.0 featured compile-time type checking and class-based syntax, such as the keywords class and extends. (While this allowed for a more flexible object-oriented programming approach, the code would still be compiled to ActionScript 1.0 bytecode, allowing it to be used on the preceding Flash Player 6 as well. In other words, the class-based inheritance syntax was a layer on top of the existing prototype-based system.) With ActionScript 2.0, developers could constrain variables to a specific type by adding a type annotation so that type mismatch errors could be found at compile-time. ActionScript 2.0 also introduced class-based inheritance syntax so that developers could create classes and interfaces, much as they would in class-based languages such as Java and C++. This version conformed partially to the ECMAScript Fourth Edition draft specification.

2006–today: ActionScript 3.0 In June 2006, ActionScript 3.0 debuted with Adobe Flex 2.0 and its corresponding player, Flash Player 9. ActionScript 3.0 was a fundamental restructuring of the language, so much so that it uses an entirely different virtual machine. Flash Player 9 contains two virtual machines, AVM1 for code written in ActionScript 1.0 and 2.0, and AVM2 for content written in ActionScript 3.0. ActionScript 3.0 provides not only a significant enhancement in performance, but also a more robust programming model that lends itself to complex Rich Internet Application development.

The update to the language introduced several new features:

 

Flash players — an overview January 15, 2008

  • Flash Lite 1.0: Flash Lite is the Flash technology specifically developed for mobile phones and consumer electronics devices. Supports Flash 4 ActionScript.
  • Flash Lite 1.1: Added support for some Flash 5 ActionScript.
  • Flash Lite 2.0 and 2.1: Added support for Flash 7 ActionScript 2.0.
  • Flash Lite 3: Added FLV video playback.
  • Flash Player 2: The first version with scripting support. Actions included gotoAndPlay, gotoAndStop, nextFrame and nextScene for timeline control.
  • Flash Player 3: Expanded basic scripting support with the ability to load external SWFs (loadMovie).
  • Flash Player 4: First player with a full scripting implementation (called Actions). The scripting was a slash based syntax and contained support for loops, conditionals, variables and other basic language constructs.
  • Flash Player 6: Added an event handling model, accessibility controls and support for switch. The first version with support for the AMF and RTMP protocols which allowed for ondemand audio/video streaming.
  • Flash Player 8: Further extended ActionScript 1/2 by adding new class libraries with APIs for controlling bitmap data at run-time, file uploads and live filters for blur and dropshadow.
  • Flash Player 9 (initially called 8.5): Added ActionScript 3.0 with the advent of a new virtual machine, called AVM2 (ActionScript Virtual Machine 2), which coexists with the previous AVM1 needed to support legacy content. Performance increases were a major objective for this release of the player including a new JIT compilation. Support for binary sockets, E4X XML parsing, full-screen mode and Regular Expressions were added. This is the first release of the player to be titled Adobe Flash Player.
 

actionscript 3.0 — data types January 15, 2008

Data types

ActionScript primarily consists of “fundamental” or “simple” data types which are used to create other data types. These data types are very similar to Java data types. Since ActionScript 3 was a complete rewrite of ActionScript 2, the data types and their inheritances have changed

ActionScript 2 top level data types

  • String – A list of characters such as “Hello World”
  • Number – Any Numeric value
  • Boolean – A simple binary storage that can only be “true” or “false”.
  • Object – Object is the data type all complex data types inherit from. It allows for the grouping of methods, functions, parameters, and other objects.

ActionScript 2 complex data types

There are additional “complex” data types. These are more processor and memory intensive and consist of many “simple” data types. For AS2, some these data types are:

  • MovieClip – An ActionScript creation that allows easy usage of visible objects.
  • TextField – A simple dynamic or input text field. Inherits the Movieclip type.
  • Button – A simple button with 4 frames (states): Up, Over, Down and Hit. Inherits the MovieClip type.
  • Date – Allows access to information about a specific point in time.
  • Array – Allows linear storage of data.
  • XML – An XML object
  • XMLNode – An XML node
  • LoadVars – A Load Variables object allows for the storing and send of HTTP POST and HTTP GET variables
  • Sound
  • NetStream
  • NetConnection
  • MovieClipLoader
  • EventListener

ActionScript 3 top level data types (see Data type descriptions)

  • Boolean – The Boolean data type has only two possible values: true and false. No other values are valid.
  • int – The int data type is a 32-bit integer between -2,147,483,648 and 2,147,483,647.
  • Null – The Null data type contains only one value, null. This is the default value for the String data type and all classes that define complex data types, including the Object class.
  • Number – The Number data type can represent integers, unsigned integers, and floating-point numbers. The Number data type uses the 64-bit double-precision format as specified by the IEEE Standard for Binary Floating-Point Arithmetic (IEEE-754).
  • String – The String data type represents a sequence of 16-bit characters. Strings are stored internally as Unicode characters, using the UTF-16 format. Previous versions of flash used the UTF-8 format.
  • uint – The uint (Unsigned Integer) data type is a 32-bit unsigned integer between 0 and 4,294,967,295.
  • void – The void data type contains only one value, undefined. In previous versions of ActionScript, undefined was the default value for instances of the Object class. In ActionScript 3.0, the default value for Object instances is null.

ActionScript 3 complex data types (see Data type descriptions)

  • Object – The Object data type is defined by the Object class. The Object class serves as the base class for all class definitions in ActionScript.
  • Array – Contains a list of data. Though ActionScript 3 is a strongly-typed language, it does not support typed Arrays. Thus the contents of an Array may be of any type.
  • Date
  • Error
  • Function
  • RegExp
  • XML
  • XMLList
 

Actionscript 3.0 an overview January 15, 2008

Filed under: Flash, Flex, Ria, actionscript — gunjank @ 5:28 am
Tags: , , , , , ,

ActionScript is a scripting language based on ECMAScript (Javascript), used primarily for the development of websites and software using the Adobe Flash Player platform (in the form of SWF files embedded into Web pages). Originally developed by Macromedia, the language is now owned by Adobe (which acquired Macromedia in 2005) which continues its development. ActionScript was initially designed for controlling simple 2D vector animations made in Adobe Flash (formerly Macromedia Flash). Later versions added functionality allowing for the creation of Web-based games and rich Internet applications with streaming media (such as video and audio).

Syntax

ActionScript code is free form and thus may be created with whichever amount or style of whitespace that the author desires. The basic syntax is similar to the C++ programming language.

ActionScript 3.0

ActionScript 3.0 has a similar syntax to ActionScript 2.0 but different set of APIs for creating objects.

var greet:* = addChild(new TextField());
greet.text = "Hello world";

Minimal ActionScript 3.0 programs may be somewhat larger and more complicated due to the increased separation of the programming language and the Flash IDE.

Presume the following file to be Greeter.as:

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);
                }
        }
}

Finally, an example of using ActionScript when developing Flex applications, again presuming the following content to be in a file named Greeter.as:

package
{
        public class Greeter
        {
                public static function sayHello():String
                {
                        var greet:String = "Hello, world!";
                        return greet;
                }
        }
}

This code will work with the following MXML application file:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" layout="vertical" creationComplete="initApp()">

        <mx:Script>
                <![CDATA[[
                      public function initApp():void
                      {
                              // Prints our "Hello, world!" message into "mainTxt".
                              mainTxt.text = Greeter.sayHello();
                      }
              ]]>
        </mx:Script>

        <mx:Label id="title" fontSize="24" fontStyle="bold" text="\"Hello, world!\" Example"/>
        <mx:TextArea id = "mainTxt" width="250"/>   

</mx:Application>

ActionScript 3.0 examples

This Hello World example uses ActionScript 3.0:

package
{
        import flash.display.Sprite;
        import flash.text.TextField;
        import flash.filters.DropShadowFilter;

        public class HelloWorld2 extends Sprite
        {
                public function HelloWorld2()
                {
                        var shad:DropShadowFilter = new DropShadowFilter (2, 45, 0x000000, 25, 3, 3, 2, 2);
                        var txt:TextField = new TextField();
                        txt.textColor = 0xFFFFFF;
                        txt.filters = [shad];
                        txt.width = 200;
                        txt.x = Math.random() * 300;
                        txt.y = Math.random() * 300;
                        txt.selectable = false;
                        txt.text = "Hello World welcome! [" + Math.round(txt.x) + "," + Math.round(txt.y) + "]";
                        addChild(txt);
                }
        }
}