I want to get a random tekst out of a txt file,
(random txt1, txt2, txt3)
txt:
&txt1=bla
&txt2=bla
&txt3=bla
Code i have so far
loadText = new loadVars();
loadText.load(“data.txt”);
loadText.html = yes;
//creating the loadVarsText function
loadText.onLoad = function() {
txt.html = true;
txt.htmlText = this.txt1;
};
If anyone knows a good turorial for this, couldn’t find anyting
this chooses a random one from the array
Math.round() rounds the number between the brackets
Math.random() picks a random number! It works like this:
to pick a random number between 0 and 10 you have to put it like this:
Math.random()*10
it actually picks a random number between 0 and 1 and you have to multiply it by the a number!
loadText = new LoadVars();
loadText.load("data.txt");
loadText.onLoad = function() {
var total;
for (var vars in this) if (typeof this[vars] == "string") total++;
txt.html=true, txt.htmlText=this["txt"+Math.ceil(Math.random()*total)];
};
that’s what i’d do… you can add as many variables as you wish in the txt file without having to edit the swf. =)