I am using a LoadVars() object inside a class. It's loading an external text file, and all is working in that regard. Here's part of the code that checks when the text file has been loaded; I named the loadvars object "load_info":
- - - - - - - - - - - - - - - - - - - - - - - - - - -
....load_info.onLoad = function(success:Boolean) {
........if (success) {
............trace("something"); //cool: this shows up.
........}
....}
- - - - - - - - - - - - - - - - - - - - - - - - - - -
But within the above function literal I need to be able to reference and set some of the properties of the class, and my first mistake was assuming that just using 'this' would do so, but it would be referencing the function object, and not the class object, as I soon found out.
I searched around and found that I probably need to use the Delegate utility in the newest version of mx 2004.
So I went over some Delegate examples, inc the one from the link:
http://www.kirupa.com/web/xml/XMLspecificIssues3.htm
and now my code in the class file looks is something like this:
- - - - - - - - - - - - - - - - - - - - - - - - - -
....import mx.utils.Delegate;
....class Something {
.... ...
....var load_info = new LoadVars();
....load_info.load("info.txt");
.... ...
....load_info.onLoad = Delegate.create(this, extract_info);
....function extract_info (success:Boolean):Void {
........trace("bla"); //this won't show in output,
........if (success) {
............trace("bla bla" + this); //and neither will this.
........{
....}
....}
- - - - - - - - - - - - - - - - - - - - - - - - - -
Now the onLoad itself does not work! (The trace messages above don't come up in Output.) As I mentioned, if I restructure the onload function in the format of the first code snippet above, then the onLoad at least works--but then i don't know how to fit in the Delegate.
So my main problem: need to be able to reference the class 'this' within the .onLoad function literal.
What am I doing wrong?
Thanks.