I’m having some problems doing some simple tasks in oop actionscript. The following code seems logical to me, but it doesn’t work. Is there a problem with the way that I am “trying” to use the this keyword.
Okay…to clarify.
- I create a Category object.
- I try to access the object’s properties via accessor methods.
At step 2, the subjects array is filled with undefined(ie. subjects[0] == undefined). Is there something I’m missing in my logic? I know that inside of the nested onLoad function the serverside page is being contacted and it returns the correct values into getVars. If I perform a getVars.toString, it looks fine. Sorry if this question is unclear… :s This is just a really simple task that I can’t get working.
[left]class Category {[/left]
[left] private var category:String;[/left]
[left] private var subjects:Array;[/left]
[left] public function Category(category:String) {[/left]
[left] this.category = category;[/left]
[left] load();[/left]
}
[left] public function getSubjects(category:String):Array {[/left]
[left] return this.subjects;[/left]
}
[left] public function load():Void {[/left]
[left] var thisRef:Category = this;[/left]
[left] var setVars:LoadVars = new LoadVars();[/left]
[left] var getVars:LoadVars = new LoadVars();[/left]
[left] // stop browser from returning cached results[/left]
[left] setVars.cacheKiller = new Date().getTime();[/left]
[left] setVars.category = category;[/left]
[left] getVars.onLoad = function(success) {[/left]
[left] if (success) {[/left]
[left] thisRef.subjects.push(getVars.subject1);[/left]
[left] thisRef.subjects[1] = getVars.subject2;[/left]
[left] thisRef.subjects[2] = getVars.subject3;[/left]
[left] thisRef.subjects[3] = getVars.subject4;[/left]
}
}
[left] setVars.sendAndLoad("getSubjects.aspx", getVars, "GET");[/left]
}
}