# \[MX Help\] Preloading variables from a TXT file

**URL:** https://forum.kirupa.com/t/mx-help-preloading-variables-from-a-txt-file/29614
**Category:** flash
**Created:** [August 28, 2003, 5:20pm UTC](https://forum.kirupa.com/t/mx-help-preloading-variables-from-a-txt-file/29614 "2003-08-28T17:20:49Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![DJ\_Lex](https://avatars.discourse-cdn.com/v4/letter/d/f17d59/32.png) [@DJ\_Lex](https://forum.kirupa.com/u/DJ_Lex)
#### Post date: [August 28, 2003, 5:20pm UTC](https://forum.kirupa.com/t/mx-help-preloading-variables-from-a-txt-file/29614/1 "2003-08-28T17:20:49Z")

</div>

I’m using a txt file that contains variables for image locations and text descriptions for a gallery.

I’m currently using the following code to load the info:  
loadVariablesNum(“info.txt”, 0);

Works great until I put in on a website. Is this a preloading issue? I did a search and could not found several conversations, but I could not get the code to apply to my situation.

Could anyone help me out on this one?

---

<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: [August 28, 2003, 5:24pm UTC](https://forum.kirupa.com/t/mx-help-preloading-variables-from-a-txt-file/29614/2 "2003-08-28T17:24:41Z")

</div>

I prefer using load vars…  
[http://www.kirupaforum.com/forums/showthread.php?s=&threadid=28606&highlight=text](http://www.kirupaforum.com/forums/showthread.php?s=&threadid=28606&highlight=text)

---

<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: [August 28, 2003, 5:27pm UTC](https://forum.kirupa.com/t/mx-help-preloading-variables-from-a-txt-file/29614/3 "2003-08-28T17:27:05Z")

</div>

That’s the code I get stuck on. I’m not sure what to put in the .onload function.

---

<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: [August 28, 2003, 5:31pm UTC](https://forum.kirupa.com/t/mx-help-preloading-variables-from-a-txt-file/29614/4 "2003-08-28T17:31:37Z")

</div>

Check this:

> **[Yahoo Small Business - Cheap Domains, Web Hosting, Website Builder, Ecommerce...](https://smallbusiness.yahoo.com/)**
>
> Yahoo Small Business Offers Cheap Domain Names, Web Hosting, Easy Website Builder, Business Email, Local Listings, and Ecommerce Solutions for Your Small Business.

This is the code i used:

```auto
function loadData() {
	loading_mc._visible = true;
	var myLoadVars = new LoadVars();
	myLoadVars.load("news.txt");
	myLoadVars.onLoad = function(success) {
		if (success) {
			loading_mc._visible = false;
			myTextField.text = this.myVar;
		} else {
			loading_mc._visible = false;
			myTextField.text = "Error loading data!";
		}
	};
}
loadData();

```

---

<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: [August 28, 2003, 5:38pm UTC](https://forum.kirupa.com/t/mx-help-preloading-variables-from-a-txt-file/29614/5 "2003-08-28T17:38:11Z")

</div>

Error loading data 😛

[AS]  
lv = new loadVars();  
lv.onLoad = function(success) {  
if (success) {  
textFld.html = 1;  
textFld.condenseWhite = true;  
textFld.htmlText = this.content  
} else {  
trace(“failed to load script”);  
}  
};  
lv.load(“textfile.txt”);[/AS]

textFld.html = 1 – Sets the HTML property of the textfield with the instance name textFld to true. So this basically means that this text will be HTML enabled.

textFld.condenseWhite = true; – Is used to get rid of annoying space between lines.

textFld.htmlText = this.content – Sets the htmlText (since we set the HTML property to true) to the value of the variable content of the object this. Since lv is an object, and we used lv.onLoad, we use this to refer to lv. content is the variable from your txt file, it would look like this:

&content=Anything goes here.

---

<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: [August 28, 2003, 5:39pm UTC](https://forum.kirupa.com/t/mx-help-preloading-variables-from-a-txt-file/29614/6 "2003-08-28T17:39:24Z")

</div>

I’m trying to replace the ‘if success’ code.

If it’s succesful I want it to go ahead and play the movie. If it fails I need it to loop. I put the following goto code and nothing happens:

myLoadVars.onLoad = function(success) {  
if (success) {  
gotoAndPlay(“thumnails”);  
} else {  
gotoAndPlay(1);  
}  
};

---

<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: [August 28, 2003, 5:43pm UTC](https://forum.kirupa.com/t/mx-help-preloading-variables-from-a-txt-file/29614/7 "2003-08-28T17:43:46Z")

</div>

Tried that other code as well and nothing happens.

I’m trying to load variables like the following:

description9=How does he do it? With a lot of talent and a little help from Strata.\<br\>\<br\>One of Matthieu’s favorite techniques involves using Strata 3Dpro combined with Adobe Photoshop to actually paint the color onto the 3D rendering.\<br\>\<br\>Step 1:\<br\>It all starts with a sketch. Matthieu conceives the image using paper and pencil.&target9=halfimage&image9=image9.jpg&thumb9=thumb9.jpg

---

<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: [August 28, 2003, 6:00pm UTC](https://forum.kirupa.com/t/mx-help-preloading-variables-from-a-txt-file/29614/8 "2003-08-28T18:00:17Z")

</div>

The attachment was to big to post. Here’s a link to it:  
[http://www.strata.com/artist.zip](http://www.strata.com/artist.zip)

---

<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: [August 28, 2003, 6:32pm UTC](https://forum.kirupa.com/t/mx-help-preloading-variables-from-a-txt-file/29614/9 "2003-08-28T18:32:56Z")

</div>

Are you using F5 or FMX ?

---

<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: [August 28, 2003, 6:36pm UTC](https://forum.kirupa.com/t/mx-help-preloading-variables-from-a-txt-file/29614/10 "2003-08-28T18:36:48Z")

</div>

FMX on the Mac. Is it not compatible? BTW, don’t laugh at my code. I’m still a rookie. 🙂

I finally did come up with an ugly solution so that I could launch the project. I set up a loop that checked for the last variable in my text file. If it was empty it would continue to loop.

But of course I would still like to do it the ‘right’ way.

---

<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: [August 28, 2003, 6:58pm UTC](https://forum.kirupa.com/t/mx-help-preloading-variables-from-a-txt-file/29614/11 "2003-08-28T18:58:23Z")

</div>

Your code was deprecated. That’s why I asked 🙂 So what are you actually trying to do here ? You said it should loop when the text file isn’t loaded, and it should continue when it is ? So like a check to make sure ?

---

<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: [August 28, 2003, 7:05pm UTC](https://forum.kirupa.com/t/mx-help-preloading-variables-from-a-txt-file/29614/12 "2003-08-28T19:05:59Z")

</div>

Yes, the idea is to check and see if the txt file (or variables) are loaded before continuing - otherwise it doesn’t run properly from a website. It always ran great on my desktop.
