Changing which .txt file is loaded for a dyn textbox

OK. I have a dynamic text box and this is the current AS I am using for it (in a separate layer, called Actions) :

[AS]loadText2 = new loadVars ();
loadText2.load(“jk87spam.txt”);
};

loadText2.onLoad = function (){
info.htmlText = this.jkinfo;
info.html = true;
};
[/AS]

Now, I have several buttons, which I have given the instance names of:
home
about
projects
links
contact

These buttons are in a movie clip within the movie clip that contains the dynamic textbox.

I would like for the textbox (instance name: info) to load a new .txt file when the relevant button is released.

Example: I release the “contact” button. The textbox (info) loads the .txt file jk87contact.txt because that is what has been specified for it to load when the contact button is released.

I have tried the following code (again, in the actions layer, following on from the previous AS code) :

[AS]_root.contact.onRelease = function(){
loadText2 = new loadVars ();
loadText2.load(“jk87contact.txt”);
}[/AS]

But when I release the button, no result. Nothing changes. And here is what I put in the jk87contact.txt file:

“jkinfo=Tralalalla lalala lallallllalaaa…!!”

  • Just in-case you thought I forgot to put “jkinfo=” :).

Any ideas??? Any suggestions???

Thanks,
JK.

you could try something like this…

set up a function to load and assign the text to the textfield:

loadText = function (file, vrbl) {
	info.html = true;
	var lv = new LoadVars();
	lv.onLoad = function(success) {
		if (success) {
			info.htmlText = this[vrbl];
		} else {
			info.htmlText = "<b>error.</b>";
		}
	};
	lv.load(file);
};

and you’d call the function like this:

contact.onRelease = function() {
	loadText("jk87contact.txt", "jkinfo");
};

hope it helps. =)

I’ll give it a whack. Cheers Kax :thumb:.

good luck! :stuck_out_tongue: :wink:

Well, kax is officially the supreme being today. The example I gave above was a simplified version of what I am using so I created a simplified .fla to just test it out, and it works perfectly. Thanks so much!!! :slight_smile: :beam:.

How might I go about setting a default .txt file which loads when the .swf first runs? (i.e. before the user selects a button to go to load a certain .txt file).

just call the function from the frame actions… :wink:

loadText("someFile.txt", "someVariable");

I’m not entirely sure what you mean but I will experiment :). Thanks.

sorry… :stuck_out_tongue:

loadText = function (file, vrbl) {
        info.html = true;
        var lv = new LoadVars();
        lv.onLoad = function(success) {
                if (success) {
                        info.htmlText = this[vrbl];
                } else {
                        info.htmlText = "<b>error.</b>";
}
};
lv.load(file);
};
**loadText("jk87contact.txt", "jkinfo");**

if you put that script in the frame actions, it will automatically load jk87contact.txt. got it? =)

Ahhh… I see. I’ve got it now =).

:thumb: :stuck_out_tongue:

Argh…

Here’s the more complex problem (which I have failed to fix). I have tried to simplify it by placing the necessary movie clips from the different .swf files into one (in the vain hope that it would solve the problem).

My buttons are in a movieclip with the instance name “menu”. My dynamic textboxes are in a movieclip with the instance name"webstart". I need to get them to work together so that when a button is clicked, it follows it’s code and gets the “info” textbox to load the relevant .txt file.

I can’t seem to get it to work (I guess because I’m rather weak on the structure of Flash when you use multiple layers and then movie clips and layers within those movie clips etc.), is there any chance you could explain how to solve it pretty pretty please? puppy dog eyes

It might be that I’m placing the code in the wrong places but I think it’s more likely that in order for them to work together, I have to use certain prefixes… (like _root and _parent)

  • Sorry for dragging this on but I have spent the good part of three hours (overall) trying to get this darn thing to work :-/.

Thanks,
JK.

hmmm… i’m not sure about this, but it sounds like this should work:

loadText = function (file, vrbl) {
webstart.info.html = true;
var lv = new LoadVars();
lv.onLoad = function(success) {
if (success) {
webstart.info.htmlText = this[vrbl];
} else {
webstart.info.htmlText = "<b>error.</b>";
}
};
lv.load(file);
};
menu.contact.onRelease = function() {
loadText("jk87contact.txt", "jkinfo");
};

you just need to fix the paths to the objects. :-\

Well, I have most of it working - all the actionscript is in the main timeline and working fine except for the buttons :-… I think it’s big problem is that the function is defined in the main timeline but the buttons are in one movieclip and then the dynamic textbox is in another movieclip.

No luck so far. I will give it another go sometime tonight or tomorrow and I’ll make sure to let you know when I figure it out :).

Thanks for all the effort kax :thumb:,
JK.

you’re welcome. =)
i hope you can figure it out on your own. :wink:

if not, you could attach your .fla, i’m sure that someone (me!? :P) can fix it for you. :beam:

Hmm… the .fla is probably too large :confused:

I will post back and then pm you about it if I haven’t solved the problem by tomorrow night (GMT time) :). Thanks for offering ;).

JK.

Well, no luck :-. I’ll pm you in a second with the details Kax :).