HELP! (AS2:OOP logic problem)

Hey guys. I’m so confused on this one. i have an array of objects that have an array of objects in them, and for some reason every instance of the object has the same array, with the same instances (the last ones created).

here are the three simplifed classes, and the code im using to access :


import SimulationLevel
class SimulationClass {
public var levels:Array = Array();

public function SimulationClass(){

//set up functions
public function addLevel(levelNum:Number,levelText:String):Void{
    this.levels[levelNum] = new SimulationLevel(levelText);

public function addOption(levelNumber:Number,optionNumber:Number,optionText:String):Void{

//accessing functions
public function getOptionText(levelNum:Number,optionNum:Number):String{
    return this.levels[levelNum].options[optionNum].Text;



import SimulationOption
class SimulationLevel{
private var levelText:String = new String;
public var options:Array = new Array();

public function SimulationLevel(levelText:String){
    this.levelText = levelText;

public function addOption(optionNumber:Number, optionText:String):Void{
    this.options[optionNumber]= new SimulationOption(optionText);



class SimulationOption{

public var OptionText:String = new String;

public function SimulationOption(OptionText:String){
    this.OptionText = OptionText;


//4.============ CODE IN FLA ==============================

import SimulationClass

var sc:SimulationClass = new SimulationClass;

sc.addLevel(1,“level one”);
sc.addLevel(2,“level two”);

sc.addOption(1,1,“lvl1, opt 1”);
sc.addOption(1,2,“lvl1, opt 2”);

sc.addOption(2,1,“lvl2, opt 1”);
sc.addOption(2,2,“lvl2, opt 2”);

trace(getOptionText(1,1); // result: “lvl2, opt1” (should be “lvl1,opt1”)
trace(getOptionText(2,1); // result: “lvl2, opt1” correct!


sigh. i just don’t understand this one. why arent the original values in them when i try and get the information? why is the array being replaced with the last created.

** AE**