Da manche Programmierer und “ActionScript2 Doof Finder” immer noch meckern über die Java-ähnliche Codeentwicklung, habe ich natürlich immer ein paar Vorteile von AS2 auf Lager, eine davon war das AS2 mehr Performance bietet, da die doppelte Anzahl an Register verwendet werden können.
Das ganze habe ich getestet an einem simplen Funktionsaufruf, ActionScript 2 Variante mit Typdeklarierung, von der ich mir am meisten Vorteile erwartet habe, da nur der Anzahl an Speiche reserviert werden muss, der tatsächlich benötigt wird.
Folgende 2 Scripte wurden getestet.
Mit Typdekleration:
[as]// attributes
var o:Object;
// namespaces
_global.com = {};
_global.com.impossiblearts = {};
// o prototype declaration
o = _global.com.impossiblearts;
// prototypes
o.Circle = function(stack:MovieClip) {
// constructor
// attributes
var s:MovieClip = stack;
var m:MovieClip;
this.__x = null;
this.__y = null;
// add property
addProperty(“_x”, this.getX, this.setX);
addProperty(“_y”, this.getY, this.setY);
m = s.attachMovie(“c”, “c” + String(s.getNextHighestDepth()), s.getNextHighestDepth());
return m;
}
o = o.prototype;
// getter/setter x-position
o.setX = function(arg:Number):Void {
this.__x = arg;
}
o.getX = function():Number {
return this.__x;
}
o.setY = function(arg:Number):Void {
this.__y = arg;
}
o.getY = function():Number {
return this.__Y;
}
// stack init
var s:MovieClip = _root.createEmptyMovieClip(“stack_container”, 1);
// engine settings
var ts:Number = getTimer();
for(var i:Number = 0; i < 1000000; i++) {
new Circle(s);
}
trace("processing time: " + (getTimer() - ts));[/as]
Ohne Typdekleration:
[as]// attributes
var o;
// namespaces
_global.com = {};
_global.com.impossiblearts = {};
// o prototype declaration
o = _global.com.impossiblearts;
// prototypes
o.Circle = function(stack) {
// constructor
// attributes
var s = stack;
var m;
this.__x = null;
this.__y = null;
// add property
addProperty(“_x”, this.getX, this.setX);
addProperty(“_y”, this.getY, this.setY);
m = s.attachMovie(“c”, “c” + String(s.getNextHighestDepth()), s.getNextHighestDepth());
return m;
}
o = o.prototype;
// getter/setter x-position
o.setX = function(arg) {
this.__x = arg;
}
o.getX = function() {
return this.__x;
}
o.setY = function(arg) {
this.__y = arg;
}
o.getY = function() {
return this.__Y;
}
// stack init
var s = _root.createEmptyMovieClip(“stack_container”, 1);
// engine settings
var ts = getTimer();
for(var i = 0; i < 1000000; i++) {
new Circle(s);
}
trace(“processing time: ” + (getTimer() – ts));[/as]
Ergebniss der Mühe, AS1 ist exakt gleich schnell(langsam) wie AS2, egal o für AS2 kompiliert oder nicht. Da macht man sich doch Gedankgen, oder das Typmodell dann noch irgendeneinen Sinn macht, außer eventuell die zweifelhaft zuverlässigen Debuggermeldungen aus dem Flash-Ausgabe Fenster, falls ein Typ falsch deklariert wurde.
AS3 Sample folgt in Kürze, ist aber vom Konzept sowieso nicht vergleichbar, da eine andere VirtualMachine benutzt wird.