well the reason why ... hmmm ... little complicated to explain ...
alright ... ActionScript is prototype-oriented, as is ECMA-script ... classes are only a syntactic sugar introduced by actionscript 2 (this has changed yet again in as3, but that's a different subject) ...
so if this is the original code:
class com.weatherwidget.City {
var zipCode:String;
var forecastText:Array = new Array(5);
}
then this is, what actually happens:
//all classes get stuffed into _global, with packages being a property path:
if (_global.com == undefined) _global.com = {};
if (_global.com.weatherwidget == undefined) _global.com.weatherwidget = {};
//and the actual definition:
_global.com.weatherwidget.City = function () {};
_global.com.weatherwidget.City.prototype = { forecastText:new Array(5) }
the prototype object of City
, that serves as prototype for instances of City
, has a property called forecastText
, which is an Array
of length 5 ... so when looking up forecastText
on an instance of City
, it cannot be found directly and will be looked up in the prototype chain ... it will be found in the instance's prototype ... thus, all instances share the same Array
...
the difference is, that the second example gets translated to:
//same thing here:
if (_global.com == undefined) _global.com = {};
if (_global.com.weatherwidget == undefined) _global.com.weatherwidget = {};
//and the actual definition this time:
_global.com.weatherwidget.City = function () { this.forecastText = new Array(5); };
_global.com.weatherwidget.City.prototype = {}
as you might have noticed, declared members are only a compiletime thing ... if nothing is assigned to them, they simply will not exist at runtime ...
well, this explenation requires, that you either know JavaScript or ActionScript 1 a little, but i hope it helps ...