-
Ximensions.com
Check if file exists
Hi
How do you use actionscript to check if a file in the same folder exists? I want to check if a textfile exists. Thank you.
-
Senior Member
Flash can not do that unfortunately. Only thing you can do is to have a special variable in the textfile, and if its not loaded within a certain amount of time, you know the textfile is not there.
If its for local use you can use the projector software from www.northcode.com
-
Monkey Moderator
Originally posted by pellepiano
Only thing you can do is to have a special variable in the textfile
Why would you need to do that these days? With the LoadVars class you get a way of handling errors so there is no need to check for a variable within the text file.
code:
txtLoader = new LoadVars();
txtLoader.onData = function(_data_){
if (_data_) {
trace("file loaded!\n\n"+_data_);
} else {
trace("file not loaded!");
}
}
txtLoader.load("myText.txt");
For web use, if you wanted to check for files before attempting to load them then you would need to use some server side script (PHP, ASP etc) to test for the files for you.
www.lexicon-design.co.uk
If we aren't supposed to eat animals, then why are they made of meat?
If Vegetarians like animals so much, why do they eat all their food?
-
Flashkit Veteran
With PHP you can check to see what files are in the same directory and then write a link to them, it is pretty cool. Only problem is I can't think of the script off the top of my head
-
Ximensions.com
Thanks
I know how to do it in PHP, but I'm going to try to see if I can contain it all in flash with the LoadVars class. I'll try it tomorrow, if I have problems I'll report here! Thanks again.
-
Senior Member
Thats good to know Lexicon.
However the code you supplied does not seem to work. It gives a "File not loaded" wether there is a textfile present or not. (which loads fine with old loadVariables though ).
-
Monkey Moderator
Thanks for pointing that out Pel.
It works fine in MX2004 exported as flash7 AS2... but not in earlier versions.
However you can use this similar code in earlier versions....
code:
txtLoader = new LoadVars();
txtLoader.onLoad = function(_data_){
if (_data_) {
trace("file loaded!\n\n");
} else {
trace("file not loaded!");
}
}
txtLoader.load("myText.txt");
www.lexicon-design.co.uk
If we aren't supposed to eat animals, then why are they made of meat?
If Vegetarians like animals so much, why do they eat all their food?
-
Senior Member
lexicon can you post a sample fla in flash mx, it would be great help for me in understanding
-
Senior Member
Thanks for that. It works great. It's now saved in my snippet code folder, and Im one good trick wiser.
-
Flashkit Veteran
Well, you can contain it all to flash except one php page which you could load into your swf with loadMovieNum("yourphppage.php",0); and then the user will never know you loaded it
-
Monkey Moderator
Sul, there is no need to send you a sample fla as everything I would put in the fla is in the post. Just copy and paste the code into a frame and make a text file in the same directory (or leave the text file out) and the jobs a goodun.
Originally posted by joejoe2288
Well, you can contain it all to flash except one php page which you could load into your swf with loadMovieNum("yourphppage.php",0); and then the user will never know you loaded it
I assume you mean loadVariables() or loadVariablesNum() joejoe, and rather than loadMovieNum()
In any case it is now recommended to use the loadVars class to load the php data, but whatever floats your boat, loadVariables() does still work.
www.lexicon-design.co.uk
If we aren't supposed to eat animals, then why are they made of meat?
If Vegetarians like animals so much, why do they eat all their food?
-
Ximensions.com
I didn't ask for the sample .fla it was hanszorg2 Thanks for your help.
I tried the LoadVars method but it's just not working. Here is what I have:
code:
var arrTypingText = new Array();
mLV = new LoadVars();
myLV.load("typingtext.txt");
myLV.onLoad = function(success:Boolean)
{
if (success)
{
arrTypingText = myLV.extTypingText.split("-split-");
gotoAndPlay(2);
}
else
{
arrTypingText[0] = "HELLO";
gotoAndPlay(2);
}
}
Then on frame 5 or so I do:
trace(myLV.extTypingText);
This returns undefined, which means its not reading the extTypingText variable from the textfile!
-
Monkey Moderator
code:
var arrTypingText = new Array();
// check spelling of myLV !!!
myLV = new LoadVars();
// declare the onLoad function before loading!
myLV.onLoad = function(success:Boolean) {
if (success) {
arrTypingText = myLV.extTypingText.split("-split-");
gotoAndPlay(2);
} else {
arrTypingText[0] = "HELLO";
gotoAndPlay(2);
}
trace("!! " + arrTypingText);
};
myLV.load("yak.txt");
www.lexicon-design.co.uk
If we aren't supposed to eat animals, then why are they made of meat?
If Vegetarians like animals so much, why do they eat all their food?
-
Ximensions.com
*Kick myself*
Thanks! It's much easier for others to pick up spelling errors, and something often overlooked!
-
Monkey Moderator
Aye, fresh eyes always help. Enjoy
www.lexicon-design.co.uk
If we aren't supposed to eat animals, then why are they made of meat?
If Vegetarians like animals so much, why do they eat all their food?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|