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 (June, 2012): Adobe announces the plan for concurrency in Flash Player and AIR – Workers.
UPDATE (January, 2013): ActionScript “Next” (aka 4.0 as I call it here) has been explicitly removed from the Adobe Roadmap.
UPDATE (August, 2013): The offerings in ActionScript are vast, but to see a more powerful language, I recommend to take a look at C# in my free, HD video training series on “Unity3D & C#“. Check it out!
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
[actionscript3]
package
{
//class must be subclassed before instantiation
abstract public class AbstractClassDemo
{
public function AbstractClassDemo()
{
}
}
}
[/actionscript3]
AbstractMethodDemo
[actionscript3]
package
{
public class AbstractMethodDemo
{
public function AbstractMethodDemo()
{
}
//Method must be overridden before usage
abstract public function sampleMethod () : void
{
}
}
}
[/actionscript3]
DestructorDemo
[actionscript3]
package
{
public class DestructorDemo
{
//constructor
public function DestructorDemo()
{
}
//destructor, called upon instance deletion
public function ~DestructorDemo()
{
}
}
}
[/actionscript3]
Enums
[actionscript3]
package
{
public enum EnumSample
{
ENUM_SAMPLE_A;
ENUM_SAMPLE_B;
}
}
[/actionscript3]
[actionscript3]
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
}
}
}
[/actionscript3]
GenericsDemo
[actionscript3]
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");
}
}
}
[/actionscript3]
MethodOverloadingDemo
[actionscript3]
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);
}
}
}
[/actionscript3]
NumericTypesDemo
[actionscript3]
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;
}
}
}
[/actionscript3]
OperatorOverloadingDemo
[actionscript3]
<pre>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…
*
*
*/
}
}
[/actionscript3]
SingletonDemo
[actionscript3]
package
{
public class SingletonDemo
{
//private constructor mean ‘Singleton’
private function SingletonDemo()
{
}
}
}
[/actionscript3]
StaticTypingDemo
[actionscript3]
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
}
}
}
[/actionscript3]
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
[private_Free member]Enjoy this members-only content!
[/private_Free member]
Unity3D & C# Training
The offerings in ActionScript are vast, but to see a more powerful language, I recommend to take a look at C#.
Some powerful C# features we love are;
- Struct
- Partial Classes
- True Singleton (private constructor)
- Ref/Out
- Full Generics (AS3 has only Vector)
- Delegates/Actions/Predicates/Lamda
- Threads
- Extension Methods,
- Operator Overloading,
All of these features and more, plus Unity3D & C# best practices are included in my free, HD video training series on “Unity3D & C#“. Check it out!