# Changing which .txt file is loaded for a dyn textbox

**URL:** <https://forum.kirupa.com/t/changing-which-txt-file-is-loaded-for-a-dyn-textbox/23308>\
**Category:** flash\
**Created:** [June 16, 2003, 9:38am UTC](https://forum.kirupa.com/t/changing-which-txt-file-is-loaded-for-a-dyn-textbox/23308 "2003-06-16T09:38:33Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![JK87](https://avatars.discourse-cdn.com/v4/letter/j/0ea827/32.png) [@JK87](https://forum.kirupa.com/u/JK87)\
**Post date:** [June 16, 2003, 9:38am UTC](https://forum.kirupa.com/t/changing-which-txt-file-is-loaded-for-a-dyn-textbox/23308/1 "2003-06-16T09:38:33Z")

</div>

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.

---

<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 16, 2003, 10:09am UTC](https://forum.kirupa.com/t/changing-which-txt-file-is-loaded-for-a-dyn-textbox/23308/2 "2003-06-16T10:09:20Z")

</div>

you could try something like this…

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

```auto
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:

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

```

hope it helps. =)

---

<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 16, 2003, 10:11am UTC](https://forum.kirupa.com/t/changing-which-txt-file-is-loaded-for-a-dyn-textbox/23308/3 "2003-06-16T10:11:33Z")

</div>

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

---

<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 16, 2003, 10:16am UTC](https://forum.kirupa.com/t/changing-which-txt-file-is-loaded-for-a-dyn-textbox/23308/4 "2003-06-16T10:16:10Z")

</div>

good luck! 😛 😉

---

<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 16, 2003, 10:18am UTC](https://forum.kirupa.com/t/changing-which-txt-file-is-loaded-for-a-dyn-textbox/23308/5 "2003-06-16T10:18:05Z")

</div>

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!!! 🙂 :beam:.

---

<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 16, 2003, 10:21am UTC](https://forum.kirupa.com/t/changing-which-txt-file-is-loaded-for-a-dyn-textbox/23308/6 "2003-06-16T10:21:33Z")

</div>

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).

---

<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 16, 2003, 10:24am UTC](https://forum.kirupa.com/t/changing-which-txt-file-is-loaded-for-a-dyn-textbox/23308/7 "2003-06-16T10:24:54Z")

</div>

just call the function from the frame actions… 😉

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

```

---

<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 16, 2003, 10:25am UTC](https://forum.kirupa.com/t/changing-which-txt-file-is-loaded-for-a-dyn-textbox/23308/8 "2003-06-16T10:25:45Z")

</div>

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

---

<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 16, 2003, 10:30am UTC](https://forum.kirupa.com/t/changing-which-txt-file-is-loaded-for-a-dyn-textbox/23308/9 "2003-06-16T10:30:00Z")

</div>

sorry… 😛

```auto
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? =)

---

<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 16, 2003, 10:32am UTC](https://forum.kirupa.com/t/changing-which-txt-file-is-loaded-for-a-dyn-textbox/23308/10 "2003-06-16T10:32:34Z")

</div>

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

---

<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 16, 2003, 10:34am UTC](https://forum.kirupa.com/t/changing-which-txt-file-is-loaded-for-a-dyn-textbox/23308/11 "2003-06-16T10:34:08Z")

</div>

:thumb: 😛

---

<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 16, 2003, 11:04am UTC](https://forum.kirupa.com/t/changing-which-txt-file-is-loaded-for-a-dyn-textbox/23308/12 "2003-06-16T11:04:56Z")

</div>

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.

---

<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 16, 2003, 11:14am UTC](https://forum.kirupa.com/t/changing-which-txt-file-is-loaded-for-a-dyn-textbox/23308/13 "2003-06-16T11:14:16Z")

</div>

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

```auto
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. :-\

---

<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 16, 2003, 5:41pm UTC](https://forum.kirupa.com/t/changing-which-txt-file-is-loaded-for-a-dyn-textbox/23308/14 "2003-06-16T17:41:58Z")

</div>

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.

---

<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 16, 2003, 9:16pm UTC](https://forum.kirupa.com/t/changing-which-txt-file-is-loaded-for-a-dyn-textbox/23308/15 "2003-06-16T21:16:27Z")

</div>

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

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

---

<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 17, 2003, 12:50pm UTC](https://forum.kirupa.com/t/changing-which-txt-file-is-loaded-for-a-dyn-textbox/23308/16 "2003-06-17T12:50:04Z")

</div>

Hmm… the .fla is probably too large 😕

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.

---

<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 18, 2003, 9:21pm UTC](https://forum.kirupa.com/t/changing-which-txt-file-is-loaded-for-a-dyn-textbox/23308/17 "2003-06-18T21:21:15Z")

</div>

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