Ok, I am using a easymvc structure (tom bray version), and i have run
into an issue that is killing me!
I am simply loading in some vars from a text file, and to do so i
wrote a utility class (to make it reusable).
Now in my class, if I populate my model var, it works fine. But it
makes that class not very reusable.
So I added a var to store the result, and made a getter method.
Now in my utility class it looks like this:
package myproject.util
{
// for text loading
import flash.events.*;
import flash.net.*;
public class LoadTextFile
{
private var _mydata:String;
public function LoadTextFile(myFile:String)
{
var req:URLRequest = new URLRequest(myFile);
var url_loader:URLLoader = new URLLoader(req);
url_loader.addEventListener(Event.COMPLETE,
onCompleteTextLoad);
url_loader.addEventListener(IOErrorEvent.IO_ERROR,
onErrorTextLoad);
//trace("called in loadTxtFile: " + myFile);
}
public function onCompleteTextLoad(e:Event):void
{
var vars:URLVariables = new URLVariables(e.target.data);
trace("LOOK HERE: " + vars.thetext);
this._mydata = vars.thetext;
trace("from mydata: " + this._mydata);
// If below added, the model is populated
// myprojectmodel.getInstance().mytext2 = vars.thetext;
}
public function onErrorTextLoad(e:IOErrorEvent):void
{
trace("Something wrong! Could not load file.");
}
public function get data():String
{
return this._mydata;
}
}
}
The traces in the class come back with the proper data. So the _mydata
var is populated.
Now from my controller: I would have a function that contained
something like this:
// new instance
var myTxt:LoadTextFile = new LoadTextFile("file.txt");
// populate my model with the results
myprojectmodel.getInstance().mytext = myTxt.data;
// another instance
var myTxt2:LoadTextFile = new LoadTextFile("file2.txt");
// populate my model with the results
myprojectmodel.getInstance().mytext2 = myTxt2.data;
trace("From Data in controller using getter: " + myTxt.data);
And this trace comes back null! WHich means it obviously never
populates my model.
Why would this happen?
It seems to be pretty basic code. But I am driving myself insane!!!!
DNK