ActionScript 4.0 Revealed
Over the past year I’ve been learning more HTML5 frameworks. Frequent leaders of our site here may remember I’ve done some analysis on HTML5 Game Frameworks as well as HTML5 App Frameworks. A major significant lack in the HTML5 ‘solution’ is the limitations of JavaScript. I was delighted to come across the official Adobe Roadmap (See ‘Members Resources’ below) for the FlashPlatform. An exciting inclusion in the roadmap is what’s up for “ActionScript Next” (Codename) or as I choose to call it ActionScript 4.0.
UPDATE (January 30th, 2013): ActionScript “Next” (aka 4.0 as I call it here) has been explicably removed from the Adobe Roadmap.
UPDATE (June 15th, 2012): Adobe announces the plan for concurrency in Flash Player and AIR – Workers.
ActionScript 4
The range of applications and content for ActionScript has shifted significantly in recent years, while the ActionScript 3 language remains virtually unchanged since its introduction in 2006. Adobe believes it is time to revise the language to carefully steer its further evolution towards greater expressiveness as well as productivity and performance gains.
From a language design standpoint, Adobe uses the following assumptions as a guide for next-generation ActionScript development:
- Increasing demand for long-term productivity benefits such as robustness, modularity, and maintainability to complement shorter-term productivity benefits characteristic of scripting languages, such as speed of development
- Demand for high performance increases
- Demand for hardware utilization increases
First, Adobe plans to make significant performance increases in the short term with a goal of continuing performance improvements over the long term. Performance is the primary goal when we approach how to evolve ActionScript. Second, Adobe aims to increase developer productivity by simplifying the language, improving tool support, and boosting bug prevention. Finally, having reduced unnecessary complexity, we will be in a position to innovate within the Flash runtimes much more quickly.
Features Currently In Discussion;
- Stringent static typing as default, with optional dynamic typing: Most stretches of most programs are expected to benefit from static typing. However, ActionScript 3 tends to lapse into dynamic typing all too easily in places where absolutely stringent static typing would be preferable. This will be corrected. Dynamic typing will still be available when needed, but it will no longer be the default for ActionScript, and it will need to be enabled explicitly.
- Type inference: Type declarations will only be necessary in certain strategic places. Everywhere else the compiler will automatically infer suitable type declarations and treat the whole program as statically typed, even though the programmer does not have to state any types. Thus the convenience of untyped programming can be approximated quite well, while providing the performance advantages of typed programming.
- Hardware-oriented numeric types: For example,
int,uint,float,float4,byte,short,long, etc. (the exact set of types is still under discussion). Currently in ActionScript 3 integer values can overflow into floating point values. This will be changed so that numeric operations will never change the underlying representation of the numeric. We foresee this addition greatly reducing implementation complexity and improving runtime performance.
These are just a couple of areas that we are focusing on. We will update this document as our thinking evolves and solidifies around how the language and virtual machine will change.
Compatibility
Its is stated that AS4 will not be completely compatible with AS3. So maybe there will be a compiler option and one must choose EITHER one or the other (similar to the mutual exclusive option between AS3 and AS2. Depending on the amount of changes in AS4 we may see a new virtual machine inside the player designed to run only the AS4. Currently there are two VM’s – one for AS3 and one for older ActionScript.
Wishlist
Many developers have been dreaming (ex. here & here) of features for ActionScript for ages. Some features I would love to see;
- Abstract Classes with Abstract Methods (ASL-18) – Well, do I have to have to say something about that wish? Basically abstract classes are such an essential thing, I am still wondering how Action Script made it to 3.0 without them. Just documenting which Methods must be overridden is not enough. And the known workarounds are really… well… hm… forget it – this is a compiler thing, which cannot be checked at runtime.
- Generics (FP-811) – The Vector class is a good start – but it’s not well supported in Flex 3 (keyword: data binding) and it’s not a generic concept. There should be something like Generics in Java that provide type checking at compile time, but can also be used for any custom class, just like in Java.
- Enums – While I have a (almost) perfect workaround for Enums in AS3, it would be great to see native language support.
- Singletons – I have a fantastic workaround for Singletons in AS3
- Improved ‘Event Listener’ syntax and performance. I like the features offered by the AS3-Signals project.
- Operator Overloading (ASL-10) – Still missing it in Java and this is, where Action Script could actually beat Java. I don’t want to have another equals method for comparing arbitrary classes for equality – I want to be able to simply override the == operator to be able to compare any two objects for equality. Or the + operator for concatenating two data structures. Just like in C++ or smalltalk.
- Method Overloading (ASL-9) – While ActionScript provides an easy way to simplify methods with long parameter lists using default values for parameters it’s not enough to justify not having method overloading. I do not want to have to write methods like doSomethingWithString(value:String), doSomethingWithInt(value:int), doSomethingWithObjectA(value:ObjectA),…
ActionScript 4.0 Code Samples (A Proposal)
AbstractClassDemo
package
{
//class must be subclassed before instantiation
abstract public class AbstractClassDemo
{
public function AbstractClassDemo()
{
}
}
}
AbstractMethodDemo
package
{
public class AbstractMethodDemo
{
public function AbstractMethodDemo()
{
}
//Method must be overridden before usage
abstract public function sampleMethod () : void
{
}
}
}
DestructorDemo
package
{
public class DestructorDemo
{
//constructor
public function DestructorDemo()
{
}
//destructor, called upon instance deletion
public function ~DestructorDemo()
{
}
}
}
Enums
package
{
public enum EnumSample
{
ENUM_SAMPLE_A;
ENUM_SAMPLE_B;
}
}
package
{
public class EnumDemo
{
public function EnumDemo()
{
trace (ENUM_SAMPLE_A); //[EnumSample ENUM_SAMPLE_A]
trace (ENUM_SAMPLE_B); //[EnumSample ENUM_SAMPLE_B]
trace (ENUM_SAMPLE_A is EnumSample); //true
trace (ENUM_SAMPLE_A is EnumSample); //true
trace (ENUM_SAMPLE_A == ENUM_SAMPLE_B); //false
}
}
}
GenericsDemo
package
{
public class GenericsDemo <AGE_TYPE, NAME_TYPE>
{
private var _age : AGE_TYPE;
private var _name : NAME_TYPE;
public function GenericsDemo(AGE_TYPE : aAge, NAME_TYPE, aName)
{
_age = aAge;
_name = aName;
//Later, in use, declare types at runtime for the generic
//var genericsDemo : GenericsDemo<Float,String> = new GenericsDemo<Float,String> (10.0, "Flash");
}
}
}
MethodOverloadingDemo
package
{
public class MethodOverloadingDemo
{
public function MethodOverloadingDemo()
{
//The implementation of this AS3 Syntax
// can now be overloaded in AS34
_sampleMethod();
_sampleMethod(10.0);
_sampleMethod("10.0");
}
/**
*
* @return void
*
*/
override public function _sampleMethod () : void
{
trace ("Parameters - None");
}
/**
*
* @return void
*
*/
override public function _sampleMethod (aValue_float : Float) : void
{
trace ("Parameters - Float: " + aValue_float);
}
/**
*
* @return void
*
*/
override public function _sampleMethod (aValue_str : String) : void
{
trace ("Parameters - string: " + aValue_string);
}
}
}
NumericTypesDemo
package
{
public class NumericTypesDemo
{
public function NumericTypesDemo()
{
//specificity helps ram usage
var sample_int : int = 10;
var sample_uint : uint = 10;
var sample_float : Float = 10.0;
var sample_float4 : Float4= 10.0;
var sample_byte : Byte = 1;
var sample_short : Short = 10;
var sample_long : Long = 10;
}
}
}
OperatorOverloadingDemo
package
{
public class OperatorOverloadingDemo
{
public function OperatorOverloadingDemo()
{
//The implementation of this valid AS3 Syntax
// can now be overloaded in AS34
this + 10.0;
this - 10.0;
this * 10.0;
this / 10.0;
this == 10.0;
this += 10.0;
this -= 10.0;
this *= 10.0;
this /= 10.0;
//Etc...
}
/**
* Add
*
* @return Float
*
*/
override public function operator== (aValue_float : Float) : Float
{
// Mimic default implementation
if (super.operator==(aValue_float) ) {
return true;
} else {
return false;
}
}
/**
* Add
*
* @return Float
*
*/
override public function operator+ (aValue_float : Float) : Float
{
// Mimic default implementation
this = super.operator+(aValue_float);
return this.toFloat();
}
/**
* Etc...
*
*
*/
}
}
SingletonDemo
package
{
public class SingletonDemo
{
//private constructor mean 'Singleton'
private function SingletonDemo()
{
}
}
}
StaticTypingDemo
package
{
public class StaticTypingDemo
{
public function StaticTypingDemo()
{
//compiler determines type by default
var sample1 = 10;
trace ("sample1: " + sample1); //10
trace (sample1 is uint); //true
var sample2 = -10;
trace ("sample2: " + sample2); //-10
trace (sample2 is int); //true
var sample3 = 10.0;
trace ("sample3: " + sample3); //10.0
trace (sample3 is Float); //true
//dynamic type in strategic places
var sample4 : int = 10.0 as int;
trace ("sample4: " + sample4); //10
trace (sample4 is int); //true
}
}
}
Next Steps
- What would you like to see in AS4? Comment below!
- Download the Official Adobe Roadmap for Flash / ActionScript 4.0 (See ‘Member Resources’ below)
Member Resources
You must be a 'Free Member' to see this content. With your access you will enjoy members-only content like this, HD video tutorials, and access to complete source code.
Ready To Join?
- Sign up for 'Free Member' level now. Its free!
- Sign up for 'Paid Member' level to enjoy much, much more! (Invite Only)
- Log in and enjoy!












I would like to add to your wishlist: destructors and float (data type)
I think another item in the wishlist should be multithreading. Come on, this is basic, and such a simple thing has cost me a lot of sweat when I absolutely needed it. I _HAD_ to mimic threading using some pseudothreading tricks that were not trivial.
Adobe has already been demoing multithreading examples coming in a future version of the Flash Player and long before they do a revamp of ActionScript. ActionScript worker threads will be part of ActionScript 3.0.
Well Couple of things extremely important to me:
– Must be backward compatible. So libraries written in AS3 should work without problem with AS4 code. I have noticed that Adobe products ( Flash in particular ) fails to be backward compatible.
– Multithreading support
– More power for developer for memory management and garbage collection. Developer friendly garbage collection.. no magic tricks please
I have been working on Flash Platform using Actionscript 3 for 5 yrs and I do have a long wishlist . But above are most critical for my needs.
“…or as I choose to call it ActionScript 4.0″
Note this might be ActionScript 4.0, however some at Adobe MAX it was suggested that while these changes are far reaching to the language, that the update might be branded ActionScript 3.x (3.1? 3.5?). It sounded like it will be more up to marketing what they end up calling it.
Beyond that great article.
http://www.adobe.com/devnet/flashplatform/whitepapers/roadmap.html
Just an FYI, but nowhere have we called the next version of ActionScript “ActionScript 4″. We are referring to it right now as ActionScript “Next” and in general, it is going to be an evolution of AS3, and not a jump like there was between AS1 to 2 and to 3.
Which is why the author of the article said he choose to call it AS4
I would love to see a liquid layout API inherent to the DisplayList. (So that it could be used within the IDE and programmatically)
Think of the following properties (top, left, right, and bottom) that could be assigned a “Guide” object.
A Guide is a dimension. It defines left or right or up and down relationships within a container and what units they use.
Each container will have an object similar to scale9Grid but for defining bounds. “liquidRect” or “liquidBounds” property could be set to any rectangle relative to inside the container. It would default to the getBounds of the object.
Guides could also have SubGuides. Which are relative to Guides instead of LiquidRect.
This would allow you to have a guide at 30% of the stage with a sub guide offset -10 pixels.
A button’s left property could be anchored to the sub guide. Resizing the stage would automatically realign that object to 10 pixels less than 30% of the width of the stage!
Best of all, designers can do most of the work for you! They can set up the rules fairly easily in the IDE and publish a SWC for you!
- scopes other than public in interface definitions
- compile time safe “annotations”
- C# style delegates (that is functions signatures as types)
- Generics
Multithreading please !!! It would be so nice to have its power at hands
~Destructor will be called when gc works?
If theyre going to redo a markup language based on as4, picking consistent nomenclature across all components’ attributes would be helpful for rapid development and maintenance. stuff like using -ing for persistant events, -able for booleans that ascribe potential states and is- for booleans which are actual states, -ed for state change events, start() for sequences instead of sometimes start() sometimes play(), using more getters and setters instead of functions with odd parameters. Initialized instead of initialize, created instead of creationcomplete, displayed instead of show; clicked; frameentered; isPlaying instead of playing();
Id like to see a trickleEvent so we dont have to use third party frameworks
integration with stage 3d
Indexedarraycollection
A datagrid that works for practical application
More utilities and easy to find documentation so you know the utilities exist
Typed associative arrays must have!!! Vector is typed but has only integer indexes. Standard AS3 array has String indexes but not typed. I need normal static typed language like Haxe or Java. AS3 good but has dynamic typing in some places. One of this cases is Array. I would like this in AS4:
var a:Array.<MyClass> = new Array.<MyClass>();
I thought they had that already with the VECTOR CLASS
Good news, So when this version is available approximately in Flex.
//request 1;==============================
//function parameters by reference;
function f( i *int )
{
i++;
}
var a:int = 10;
f(a);
trace (a); //result 11;
//request 2 ======================
//remove method for Array, workable in for each block;
var a:Array;
for each (var e:Element in a)
{
if(e.needRemove)
{
a.remove(element);
}
}