PDA

View Full Version : Tutorial for Read from TXT


TMLewiss
06-03-2005, 06:05 AM
I want to load a bunch of information into textboxes and texfields all from a *.txt file. Anyone know of a good tutorial for that in MX 2004? Thanks in advance for any help on this topic.

merlinvicki
06-03-2005, 12:04 PM
Hi,

Check out this sample:

http://www.merlinvicki.com/samples/textenhancements.zip

This loads an html file so u can actually use text formatting as well.

TMLewiss
06-03-2005, 04:55 PM
Thanks, anyone else know of anything else that can help?

cxn926
06-03-2005, 07:00 PM
Hi,

Check out this sample:

http://www.merlinvicki.com/samples/textenhancements.zip

This loads an html file so u can actually use text formatting as well.

but i think TMLewiss is looking for a text box not a componet

TMLewiss
06-03-2005, 10:02 PM
Here is what I am trying to do:

The flash video is just a 3 tab menu. When you click on the first tab it loads a bunch of personal information into tables already created, then when you click on the second tab, it loads a whole bunch of other information into premade tables, and same for the 3rd. The problem is, I have 150 people I have to do it for, and I really don't want to have to update the flash video every time. If I can figure out how to read from text files I ca just change them, then the flash can load the new information. I know I could always use php and mySQL, but it is not my web server and I don't want to screw with the databases.

dixieflatline
06-03-2005, 10:46 PM
Hi,

Would loading the dynamic content from XML files suit your objective?

http://www.actionscript.org/tutorials/intermediate/XML/index3.shtml

TMLewiss
06-04-2005, 12:56 AM
If someone can simply tell me how to take a file containing this:

Wooty Wooterson
Nooby Nooberson

Now just take those two things and populate two text fields or text poxes or anything like that. If I know how to do that I can expand on it easily.

lelales
06-04-2005, 01:18 AM
Load Vars should point you in the right direction.

You can load from a database using PHP or other programs, or you can load text from a static text file.

TMLewiss
06-04-2005, 03:50 AM
Thanks that is what I needed, I will study up on that

Egg
06-04-2005, 04:48 AM
Hi
Try something like this:
loadVariablesNum("http://www.domain_name.co.uk/text/textfile1.txt?Ran="+random(500),0);

The textfile will need to look like this:
name1=Wooty Wooterson &name2=Nooby Nooberson&Loaded=Loaded
Egg

merlinvicki
06-04-2005, 06:11 AM
but i think TMLewiss is looking for a text box not a componet

:confused: but the link I put up is not for a component. It loads an external html file into ur swf with raw actionscript code u can modify.

and the post from EGG is what u do to load a txt file. He/She just missed an onload event check for the txt file which is important if u r loading the file on the web.

TMLewiss
06-04-2005, 06:32 AM
No no, I got it. I used what egg showed. I use that txt file to load so much data, the txt file is 113 kb. That is huge for a unformatted text file. But I also made a program in VB .NET that loads the data and lets me edit it or add a new entry at ease. So it worked out great! Thanks guys.

Egg
06-04-2005, 01:12 PM
Thats fine. Merlinvicki is correct about checking the file is loaded. I always set up a loop to check if the text file is loaded.

if (Loaded=='Loaded';) {
play();
} else {
gotoAndPlay('loop');
}

Egg

MaxFarago
06-04-2005, 11:33 PM
What's the significance of the +random(500) added to the URL? Can it not just link directly to the .txt. file?

Also, if one were to complete this in this way, would this be updatable? So for instance, if I had only two textFields, name1 and name2, and then my txt file had a name3 even though the textField didn't exist, would it be possible to tell flash to create a new text field called name3, so that the data would enter it?

I was wondering if maybe it's possible to create an array that creates new cells for each name1, name2, etc. This array could hold all of the information in separate cells, and then you could loop through it, creating a textfield for each cell as you go through, and assign the text to the corresponding field.

Would this be possible?

Egg
06-05-2005, 12:23 AM
Max
The significance of the random variable at the end of the url is to fool the browser that it's being requested to load new information. This avoids cacheing of the text file, so it's loaded anew on each request. You could link directly to the text file, and as long as your sure it's not going to change in content, that would be fine, but if it changes regularly, the changes wouldn't be seen as the browser would load it from cache, not the server.

On the second part of your question, yes this possible. The text file could hold 100 variables, which would all be downloaded. You could then load these different variables into whatever text field you wish via

name1=textFileVariable1;
name2=textFileVariable2;

then later in the timeline or due to a button event etc:

name1=textFileVariable57;
name2=textFileVariable99;

Arrays are the best way to handle these variables if you have a great deal of them. They are also a great way of reducing the number of variables that need to be stored in txt file.
As an example: I needed to have a text file that contained x number of street names, each street name required 4 further variables attached to them, ie 5 variables per street name, so if I had 20 street names, that would need writing a text file with 100 variables.

By loading a single variable into an array and using the split command to produce more arrays, it was possible to use only one variable in the text file, and have a/s do the rest.

streets=Hopkins Lane;864;98;-4920;-170:Harbour Cres;898;160;-5270;-800:Hordle St;820;237;-4450;-1600:Hordle Place;816;234;-4450;-1560:Hill Rd;804;224;-4290;-1460:Highfield Ave;721;282;-3450;-2040:Harcourt Ave;667;226;-2850;-1500:Hudson Close;658;359;-2790;-2880:Hamilton St;617;150;-2370;-700:Haven The;638;250;-2590;-1720:Howard Ave;600;320;-2190;-2480:Hazelville Cl;561;355;-1770;-2840:Hankin Ave;471;367;-790;-2980:Hewitt Rd;444;389;-550;-3140:Holyrood;605;312;-2250;-2400:Hall Lane;685;326;-3090;-2540:High St;820;226;-4470;-1500

You can now split the variable 'streets' at ':' and further at ';'

Egg

MaxFarago
06-05-2005, 01:24 AM
OK, so here's my last question: how exactly do I load the vars into the array. I'm imagining something like this:


var entryArray:Array = Array();
var varLength:Number = new Number(1);
for (i=0; i<varLength; i++)
{
if (done == "undefined")
{
entryArray.push(nextVar);
varLength++;
}
}


But my problem is with the line where I want to push the variable into the array. How can I load the variables so that each one loads and is stored in a new array cell?

And thanks for the help so far Egg, I appreciate it!

Egg
06-05-2005, 01:46 AM
Hi Max
It's getting late here so I can't give you a full answer but here's part of the A/S I used in the example above:

// create an Array named streetsArray using this variable and split it at every colon
streetsArray = streets.split(':');
// sort this array into alphebitical order
streetsArray.sort();
// counts the number of variables in the array to determine the number of buttons
noOfButtons = streetsArray.length
// splits streetsArray into a number of arrays named button(number)Array
button0Array = streetsArray[0].split(';');
button1Array = streetsArray[1].split(';');
button2Array = streetsArray[2].split(';');
button3Array = streetsArray[3].split(';');
button4Array = streetsArray[4].split(';');


// this sets up the button names
button0name = button0Array[0];
button1name = button1Array[0];
button2name = button2Array[0];
button3name = button3Array[0];
button4name = button4Array[0];

destination = 'button' + noOfButtons
gotoAndStop(destination);


I don't know if you will be able to unravel this. (I'm a crap coder, I just muddle thru until I find something that works)
But you should be able to see how it takes the variable 'streets' in the earlier example, creates an array, splits this further into streetsArray0, streetsArray1 etc

Hope this helps for now. Hopefully a code expert will pass by an explain it better than I can

(I know the reference to Buttons may be confusing but the buttons with street name, when rolled over, highlight the small scale x & y co-ordinates, and when clicked on goto the co-ordinates of a zoomed map)

Of course I should have used a For Next routine for the above using the Array Length..... but as I said, my coding is *****


Egg