The code below was kindly provided (dawsonk ) to help me create a random name selector for the classroom. It works great but it doesn't like a space between two words. So I can't copy and paste a list with name and surname. It comes out with nonsense characters in the space.
Any ideas on how to remedy this?
Thanks
frame 1
stop();
var name = new Array();
var colour = new Array();
var letter = new Array();
function getRandInfo(fileName, info) {
var myLV = new LoadVars();
myLV.onLoad = function(success) {
if (success) {
for (var i in myLV) {
var tmpArray = escape(i).split("%0D%0A");
break;
}
var infoArray = new Array();
for (var i = 0; i<tmpArray.length; i++) {
if (tmpArray[i].length != 0) {
infoArray.push(tmpArray[i]);
}
}
var count = Number(random(infoArray.length));
info.push(infoArray[count]).toString();
play()
} else {
info.push("error").toString();
trace("Ooops there is something wrong - better check it out.");
}
};
myLV.load(fileName);
}
Fiddled around with various things and still comes up with %20 in the space.
I've attached a zip folder with the fla. and text file- I just slimmed it down to the one variable. I would be great if you had a chance take a look to see what I'm doing wrong. If not, thanks anyway for all your help on this.
stop();
var name = new Array();
var colour = new Array();
var letter = new Array();
function getRandInfo(fileName, info) {
var myLV = new LoadVars();
myLV.onLoad = function(success) {
if (success) {
for (var i in myLV) {
var tmpArray = escape(i).split("%0D%0A");
break;
}
var infoArray = new Array();
for (var i = 0; i < tmpArray.length; i++) {
if (tmpArray[i].length != 0) {
infoArray.push(tmpArray[i]);
}
}
var count = Number(random(infoArray.length));
info.push(unescape(infoArray[count]) ).toString();
play();
}
else {
info.push("error").toString();
trace("Ooops there is something wrong - better check it out.");
}
};
myLV.load(fileName);
}
getRandInfo('names.txt',name);