Quote:
Originally Posted by Gunderak
Also curious, why this didn't work.
PHP Code:
//#GS3
class Person extends TStaticVar{
var nickname:string;
}
function onCreated():void{
//Create an array of type Person
var list:Person[];
//Create some Person objects.
var me:Person = new Person();
me.nickname = "Nick";
var them:Person = new Person();
them.nickname = "Someone";
//Add them to the list
list.add(me);
list.add(them);
//Echo each Person element in the list
for(var someone:Person in list){
echo("Name: "@someone.nickname);
}
}
It does nothing, no errors either.
|
In the above code, the "list" variable was not initialized. The GS3 compiler currently fails to compile uninitialized variable declarations.
As a workaround, the following code should work:
PHP Code:
//#GS3
class Person extends TStaticVar{
var nickname:string;
}
function onCreated():void{
//Create an array of type Person
var list:Person[] = {}; // Do not forget to initialize.
//Create some Person objects.
var me:Person = new Person();
me.nickname = "Nick";
var them:Person = new Person();
them.nickname = "Someone";
//Add them to the list
list.add(me);
list.add(them);
//Echo each Person element in the list
for(var someone:Person in list){
echo("Name: "@someone.nickname);
}
}