flash data integration:
It's about "asymmetry" in LoadVars(). I want to load an array, but didn't know
how to actually story it in the external file. So I used LoadVars.toString() to
show me the format and when I used it, it doesn't work. I guess I am missing
some step. I am attaching the code.
/* Asymmetry in LoadVars() */
/* Idea: I want to load an external variable, in this case an
array, from an external file (data.txt), using LoadVars().
The question is how to store an array in the external file?
I use the LoadVars.toString() method to see how LoadVars()
stores an ActionScript array */
// First, I create the array
var myArray1:Array = new Array("cat","dog","pig");
// Then I create the variable using LoadVars()
var myVars1:LoadVars = new LoadVars();
myVars1.collection = myArray1;
// Then I use LoadVars.toString() to see how to store it
trace(myVars1.toString());
// The output is
// collection=cat%2Cdog%2Cpig
/* Logically, if I store the above output into data.txt and
use LoadVars() to load the array variable into an ActionScript
array, it should work. */
var myVars2:LoadVars = new LoadVars();
var myArray2:Array = new Array();
myVars2.onLoad = function(ok) {
if(ok) {
myArray2 = myVars2.collection;
}
}
myVars2.load("data.txt");
trace(myArray2);
// There is no output
/* When checking the Debug->List Variables, this is what gets stored
in myArray2:
Variable _level0.myArray2 = "cat,dog,pig\r\n"
If one uses trace(myArray2), there is no output...
====================================================================
The question is, why isn't this process symmetric? I asked the
method itself to show me how to store an array, and when I use
that format, it does not load it */