# \[FMX\] Loading TXT and Strings

**URL:** <https://forum.kirupa.com/t/fmx-loading-txt-and-strings/24147>\
**Category:** flash\
**Created:** [June 26, 2003, 3:08pm UTC](https://forum.kirupa.com/t/fmx-loading-txt-and-strings/24147 "2003-06-26T15:08:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![zaok](https://avatars.discourse-cdn.com/v4/letter/z/45deac/32.png) [@zaok](https://forum.kirupa.com/u/zaok)\
**Post date:** [June 26, 2003, 3:08pm UTC](https://forum.kirupa.com/t/fmx-loading-txt-and-strings/24147/1 "2003-06-26T15:08:07Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 26, 2003, 4:06pm UTC](https://forum.kirupa.com/t/fmx-loading-txt-and-strings/24147/2 "2003-06-26T16:06:46Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 26, 2003, 4:51pm UTC](https://forum.kirupa.com/t/fmx-loading-txt-and-strings/24147/3 "2003-06-26T16:51:23Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 26, 2003, 5:55pm UTC](https://forum.kirupa.com/t/fmx-loading-txt-and-strings/24147/4 "2003-06-26T17:55:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 26, 2003, 6:23pm UTC](https://forum.kirupa.com/t/fmx-loading-txt-and-strings/24147/5 "2003-06-26T18:23:51Z")

</div>

maybe… 😛

this will be hard !

\*\*\*\*…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 26, 2003, 6:24pm UTC](https://forum.kirupa.com/t/fmx-loading-txt-and-strings/24147/6 "2003-06-26T18:24:50Z")

</div>

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, i_20, 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]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 28, 2003, 12:49pm UTC](https://forum.kirupa.com/t/fmx-loading-txt-and-strings/24147/7 "2003-06-28T12:49:45Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 28, 2003, 4:21pm UTC](https://forum.kirupa.com/t/fmx-loading-txt-and-strings/24147/8 "2003-06-28T16:21:36Z")

</div>

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 ☹
