PDA

View Full Version : List specific lines from a dynamic text


ClaudioAdriano
07-27-2005, 03:56 AM
Ok so I have an external .txt file with dozens of lines in it, and I want that flash displays in it specific lines, that star all with the same letter.

For example, I want that flash only display the lines that start with letter "A".

I thought it would be something like this:


Data = new LoadVars();
Data.onLoad = function() {
for (i = 0; i < array.lengh-1; i++){
if (array[i].charAt(0) == "A")
text_in_flash.htmlText = this.var_on_textfile;
}
};
Data.load("textfile.txt");


Anyone knows what's wrong ? Or how can I do that ? thanks ...

Curly Brace
07-27-2005, 05:15 AM
Well... to load some data from the txt file you need to put the text to the file like following: &some_variablle=some_value&other_variablle=other_value etc. So, when to load finishes you have theese variables out to your LoadVars object (in our example you'll have Data.some_variable=some_value).
Here's an example I've made:
text_file.txt

&txt_data=sdlgkjfhdslkgjhdlfkjghldksh
sdflgkjhsfdglkjhlsfkg
sdfkgjhdfslkgjhldksfjghl
akjdsfhgliuh
sdglkjhtoypoiyup
abnkjv nlkcjvnb&

ActionScript

Data = new LoadVars();
Data.onLoad = function(success) {
if (success) {
lines = this.txt_data.split("\r\n"); // "\r\n" are the new line symbols that created when you press 'enter' key in a text editor
for (i=0; i<lines.length; i++) {
if (lines[i].substr(0, 1) == "a") {
trace(lines[i]);
}
}
}
};
Data.load("text_file.txt");

result

akjdsfhgliuh
abnkjv nlkcjvnb

ClaudioAdriano
07-27-2005, 02:56 PM
Well, I've tried it but it doesn't work ... what it does is to show up the results all in the same line.

Here's my work ... can you see what am I doing wrong ? Thanks for your help...

Curly Brace
07-27-2005, 07:17 PM
Here's the working one. You just needed to show in your text field all that was traced, not the whole lines variable value.

ClaudioAdriano
07-27-2005, 08:22 PM
Thanks ... it is working, but now there seems to have another problem ...

It seems that when there are many lines that start with that letter, Flash doesn't display them all :(

ClaudioAdriano
07-27-2005, 08:34 PM
Just to say that I solved that error ... there where "&'s" inside the text ... thanks for all your help.