Verify if textfile exists (bool)

Hey!

Wanted to know if it is possible to make a bool-variable in flash that is set to ‘false’ by default. It then checks if a file exists at a certain location, and if so, the bool-variable is set to ‘true’ ?

Something like:

if (c:/myTextfile.txt == true){do stuff here;}

What would be the correct code?

Thanx.

Well, LoadVars would check if that file exists, and if its not, then u could assign the textField something like “Error loading file”, or “TextFile Does’nt exist”.

dataHandler = new LoadVars();
dataHandler.onLoad = function(success) {
if (success) {
myTextBox.text = "File exists";//or u could assign the target variable, it should look like: (without the quotes) "myTextBox.text = this.ExternalVariable"
} else {
myTextBox.text = "File does'nt exist";
}
};
dataHandler.load("textfile.txt");

Hope it helps,

yours,
h88 :bandit:

i don’t think you can’t check if a file exists with Actionscript only. h88’s method is clever, but it’s a workaround. If you really want to know if a file is in a directory, you’ll have to use PHP.

pom :slight_smile:

hum :-\ workaround, does that exist?

H88’s method works, but you have to wait for the file to load completely before Flash knows that the file exists. Somebody else asked this same question in the following thread:

http://www.kirupaforum.com/showthread.php?s=&threadid=9872

I tried to answer the question there, but basically it involves the getBytesTotal() method, which is much quicker (I think) than loading the whole file.

I’m actually curious to see if that works. If anybody tries it out and it works, plz lemme know. Thanks.

-Al

would this work?

if you place the code to upload the variables on the mc instance using an:

onClipEvent (data) {
}

then the data has to load for that statement to execute (i think)

so you could do something like (excuse the syntax):

fileExists = false //set the boolean

onClipEvent (data) {
//do stuff
fileExists = true //set the boolean
}

// check boolean
if fileExists = false //the data was not loaded, therefore file doesn’t exist
else //the file does exist

that’s how i would do it in another language - so i’m hoping it works (not had time to try it yet)

sorry everybody - i was replying to the first post and suddenly there was all these replies! (i left my browser open for a long time)

i used h88’s code as he set it out in his reply

i just have to assume that if the data isn’t there then the file doesn’t exist