[FMX] Loading TXT and Strings

hello !

i have a .txt full of words (strings) devided by lines and separated with ; and i want to be able to load 1 random line and the first string of it…

ex :

ALI;DALI;IDEAL;DELIRA;PREDIAL;REPELIDA
AMO;MATO;MORTA;MOSTRA;MAESTRO;BATERMOS

i want to be able to load “ALI” for example. and then load DALI etc etc

i used loadvariablesnum to load the text, but maybe that shouldn’t be the best option…

can anyone help me ?

Text File:

myVars=ALI;DALI;IDEAL;DELIRA;PREDIAL;REPELIDA;AMO;MATO;MORTA;MOSTRA;MAESTRO;BATERMOS

Frame in Flash…
[AS]myLV = new LoadVars();
myLV.onLoad = function(success){
if (success){
//pull string into Flash and split it at the “;” to parse it into an array
myVarsArray = this.myVars.split(“;”);
//anything else you want to do here…
} else {
trace(“file failed to load”);
}
};
myLV.load(“textFile.txt”);[/AS]

Thats a quick example, but I am not exactly sure what you are trying to do. Do you want it to go in order? Or be random? How are you displaying the info?

well… i think it’s kind of hard to do/explain

i have to do a game like. i give a word “ALI” then i show you “D _ _ _ " and you have to guess it’s “DALI” then i show you " _ E _ _” and you have to guess it’s “IDEAL”. make a word with previous letters + one new, that is shown. well, the problem is… how can i make flash know which letter apears in the final word and not in the first one. hard isn’t it ?

So if I have it correct you want it to be like a hangman thing?

maybe… :stuck_out_tongue:

this will be hard !

****…

Ok, if that was what I was thinking (the hangman type game), I was trying stuff out and I gotta say… if you don’t know AS, you are getting ahead of yourself. I am working on it and still have a buggy version, but quite a bit of “advanced” coding.

Just to make sure we are on the right page… open a new document, paste this on a frame (I hope you have Verdana installed, if not it will show your default font)…

[AS]//Load variables in
myLV = new LoadVars();
myLV.onLoad = function(success) {
if (success) {
myVarsArray = this.myVars.split(“;”);
getWord();
} else {
trace(“file failed to load”);
}
};
myLV.load(“vars.txt”);
//set text formatting options
myTF = new TextFormat();
myTF.font = “Verdana”;
myTF.size = 12;
//create array to store parsed word
var parsedWordArray = ;
//create clip to hold textboxes
this.createEmptyMovieClip(“wordContainer”, depth++);
//function to randomly choose a word
function getWord() {
newWord = myVarsArray[random(myVarsArray.length)];
trace(newWord);
parseWord();
}
//function to parse the word into seperate textboxes
function parseWord() {
ranLetterShown = random(newWord.length);
for (var i = 0; i<=newWord.length; i++) {
parsedWordArray* = newWord.charAt(i);
wordContainer.createEmptyMovieClip(“textBoxContainer”+i, i);
wordContainer[“textBoxContainer”+i].createTextField(“letter”+i, i, i20, 20, 15, 20);
wordContainer[“textBoxContainer”+i][“letter”+i].border = true;
wordContainer[“textBoxContainer”+i][“letter”+i].maxChars = 1;
wordContainer[“textBoxContainer”+i][“letter”+i].restrict = “A-Z”;
wordContainer[“textBoxContainer”+i][“letter”+i].setNewTextFormat(myTF);
if (i == ranLetterShown) {
wordContainer[“textBoxContainer”+i][“letter”+i].selectable = false;
wordContainer[“textBoxContainer”+i][“letter”+i].text = parsedWordArray
;
} else {
wordContainer[“textBoxContainer”+i][“letter”+i].type = “Input”;
}
wordContainer[“textBoxContainer”+i][“letter”+i].letterVar = i;
wordContainer[“textBoxContainer”+i][“letter”+i].onKillFocus = function() {
if (this.text == parsedWordArray[this.letterVar]) {
trace(“correct”);
this.selectable = false;
this.type = “dynamic”;
} else {
trace(“incorrect”);
this.text = “”;
}
checkWord = “”;
checkValidity();
};
}
for (var r = newWord.length; r<=20; r++) {
wordContainer[“textBoxContainer”+r].removeMovieClip();
}
trace(parsedWordArray);
}
function checkValidity() {
for (var j = 0; j<parsedWordArray.length; j++) {
checkWord += wordContainer[“textBoxContainer”+j][“letter”+j].text;
trace(checkWord);
trace("new: "+newWord);
if (checkWord == newWord) {
trace(“COMPLETED WORD!”);
getWord();
}
}
}
//position word
wordContainer._x = 275-wordContainer._width;
wordContainer._y = 200;
[/AS]

[edit]
Oh and in the same directory you save this create a text file called “vars.txt” and put this in there…

myVars=ALI;DALI;IDEAL;DELIRA;PREDIAL;REPELIDA;AMO;MATO;MORTA;MOSTRA;MAESTRO;BATERMOS

You will have to remove the space created by the forum (the one with the I and the D in REPELIDA).
[/edit]

i want to randomly chose a line, but the first word on it!
and then proceed with the “guessing” thing…

i think i wouldn’t be able to do this, it’s to hard !

:hangover:

Yeah, things like this sound easy in English, but when translated to AS it turns out to be more difficult than it sounds :hangover:

Either that or the fact that I overthink everything isn’t allowing me to find a simpler way :-\

Sorry :frowning: