[FMX] most MXish way of laoding external .txt file?

I’m trying to get an external text file to load into my movie… I read the tutorial about the scrollbar w/ external text file but it’s not really clear and it seems somewhat out dated…
I’m anxiously awaiting ASDG2 coming out on December 19th, but meanwhile, if one of you gurus could enlighten me real quick, I’d appreciate it a lot.

what would the code look like to load a text file called “theText.txt” into a text field called “theField_mc” created with AS itself attached to a mc called “theMC_mc” created w/ createEmptyMovieClip(); ?

I’m trying to do this %100 AS, no instance manually put on the stage.

THX!

Here:

_root.createTextField("theField_mc", 1, 1,1,400,400 );
myLoadVars = new LoadVars ();
myLoadVars.onLoad = function(success) {
   if (success){
      trace ("your file loaded correctly");
      theField_mc.text = myLoadVars.TargertExternalVariable;
   }else {
      trace ("error loading document");
   }
};
myLoadVars.load ("theText.txt");

And put in mind, there is no out-dated MX Tutorial in Kirupa.com

h88 :stuck_out_tongue:

ok, I copy/paste your example in the AS editor and your LoadVars is nice and blue but the one I got from the tutorial is not… I wondered about that loadVars for a while last night 'cause the reference didn’t mention anything about it and if it wasn’t a built in function, then, where else in the tutorial’s .fla was it referenced? After looking on every layer of every object, I got annoyed/discouraged… But when I saw your LoadVars blue in the editor it hit me: “LoadVars” and not “loadVars”…
I was about to blame myself but I’m very vain so I checked the tutorial:


loadText = new loadVars();
loadText.load("kirupa.txt");
//creating the loadVarsText function
loadText.onLoad = function() {
		scroller.text = this.kirupatext;

looks like it’s not entirely my fault after all :slight_smile:

Still a question thought: is there a rule as what function starts w/ capital letter? usually, it always starts with small letter… That’s what got me…

btw, love Kirupa.com :slight_smile:

ok… need more help :wink:

this works:
I put a text field called: “txtField_mc” on stage manually and this code on the 1st frame:


loadText = new LoadVars();
loadText.load("bio.txt");
loadText.onLoad = function() {
	_root.txtField_mc.text = this.bio;
};

but this doesn’t:
I don’t put anything on stage but add the createTextField thingy…


_root.createTextField("txtField_mc", 20, 20, 440, 190);
loadText = new LoadVars();
loadText.load("bio.txt");
loadText.onLoad = function() {
	_root.txtField_mc.text = this.bio;
};

ok, I decided to go for the manually created text field on the stage since the resulting .swf file displays the text beautifully like that…
BUT, if I load that .swf into the main movie with loadMovie, the text fanishes!!!
This is kinda driving me crazy… Anyone knows why it would do that?
thx.

Can you zip-up what u’ve got? :slight_smile: Txt,swf’s, fla…

it’s cool, I figured it out. I’m new to loadMovie and I didn’t realize that _root meant “root” of the main swf, not the loading one… :slight_smile:
I got it all working: text field created dynamicaly filled with a text file text :slight_smile:
But I ran into some kinda bug…
One of the loaded movie’s text doesn’t want to stay in the textField box… It bleeds even outside of the loaded mc on the main movie’s stage until the border of the main .swf! I forgot to mention that the problem comes from the fact that I’m embedding the font to display… with Arial, everything’s fine… wasting hours on little details… but I want it to look good!