I got this class, let’s call it: Klass.
The class Klass has a parameter for its constructor that is an array with a default value of null.
I create an object of the class Klass inside another class, lets call it: “MotherClass”.
Now is when it gets weird, after I instance the object Klass, the constructor of Klass gets called again, just right after the constructor of the MotherClass ends (I placed a breakpoint and I followed step by step), with null constructor parameters.
The thing is, I don’t have the stack trace of anything that is calling the constructor of Klass for the second time, no clue what could be calling that constructor again…
Any ideas?
Thanks.
(Klass implements an interface, and I’m making an instance using an array, not sure if that is affecting anything)
added code as requested:
this is the class MotherKlass:
public class Unit extends EntityVO{
public function Unit(level:int = 1)
{
//init vars and stuff
//...
//
initLevelData();
applyLevel = level;
}
private function initLevelData():void {
levelData[1] = [500, [[Spawn, this.entityToSpawn.type, this.entityToSpawn.level, 120]], "unit_level1"];
levelData[2] = [1000, [[Spawn, this.entityToSpawn.type, this.entityToSpawn.level, 90]], "unit_level2"];
levelData[3] = [2000, [[Spawn, this.entityToSpawn.type, this.entityToSpawn.level, 80]], "unit_level3"];
levelData[4] = [5000, [[Spawn, this.entityToSpawn.type, this.entityToSpawn.level, 60]], "unit_level4"];
}
override public function set applyLevel(level:int):void {
power = power / maxPower * levelData[level][0];
maxPower = levelData[level][0];
behavior = levelData[level][1];
for (var i:int = 0; i < behavior.length; i ++){
_behaviorSteps[i] = new behavior[i][0](behavior[i].slice(1));
_behaviorReqs.push(_behaviorSteps[i].req);
}
}
}
}
}
and this is Klass:
public class Spawn {
public class Spawn implements IBehavior
{
private var _entityType:String;
private var _entityLevel:int;
private var _spawnRate:int;
public function Spawn(params:Array = null){
//had to put the if because of the second weird call to the constructor with null
if(params){
_entityType = params[0];
_entityLevel = params[1];
_spawnRate = params[2];
}
}
}
}
}
I’m receiving an instance of the class Unit throught Cirrus, and using RegisterClassAlias to deserialize the object. When I do that, seems like an instance of Spawn must be automatically instantiated for some reason. That is why you cant pass ojbects without default arguments. In this case, it throws an error because I’m using (params[0]) the argument that is null. I use Cirrus in other parts of my code, and it works ok because there are all ints and strings in their parameters constructors.