Flash Vista - Acasa
Site-ul de Flash al Saptamanii
The Two Tales
Informatii despre Site | Arhiva
Meniul Principal
Acasa
Linkuri noi
Cele mai votate
Cele mai populare
Alegerea editorului
Cauta

Flash Tutorials
Flash Resources
Stiri FlashVista
Flash Templates
Flash Intro Templates
Website Templates
Flash Games
Flash Books
Sondaje FlashVista
Harta Site-ului


Un Link la intamplare
English
Entheos
Informatii despre Site | Incearca altul
FlashVista
Intra
Inscriere
Subscrie

Adauga legatura
Modifica link
Favorite
Sugereaza categorie

Fa reclama
Sprijiniti-ne
Multumiri
Contact

Flash Templates:

More Templates ...

Lista mail
utilizator

Parola



Inscrie
Ai uitat parola ?
Partner websites
Free Hit Counter
Free Seo Tools
Free Tutorials
Free Video Tutorials
Forum signatures
Best Free Scripts
Wii Fit
Wii Fit News
Cool Tech Gadgets
Other Resources
Sugereaza
Sugereaza acest sit unui prieten


Lista mail
Status: Nu esti logat

Romanian English German French Spanish Italian Portuguese Russian Polish Finnish Dutch Swedish Thai Romanian Traditional Chinese Simplified Chinese
CautaNu esti logat
Cuvant cheie: Cauta dupa: Cautare avansata


Checking if a file exists with ActionScript


NEW Flash Tutorials in Video Format - Powered by LearnFlash.com: 45 minutes of flash tutorials now available in streaming format or download. Topics Include flash for beginners, text effects, actionscripting, audio/video, flash 8 and more.


Printer version



by Guy Watson
www.flashguru.co.uk

Sometimes it is necessary to determine if a file exists using actionscript, for example when you have a preloader cue, that loads a series of .jpgs one after another, if one of the files doesnt exist then the cue wouldnt traverse any further, you could of course use a timeout in that scenario but why not just check if the file exists before loading it, so that if necessary you can move onto the next item in the cue almost instantly. It is possible to determine whether a file exists using the success parameter of the onLoad event handler, the problem lies in the fact that the onLoad event handler for movieclips doesnt work, so to check if an .swf file exists, or an image, you will need to use this method...

Here is a little example, that checks to see if a .swf file exists, and if it does, then it loads it into a movieclip.


fileExists=new LoadVars();
fileExits._parent=this;
fileExists.onLoad=function(success)
{
//success is true if the file exists, false if it doesnt
if(success)
{
//the file exists
var nm=this._parent.createEmptyMovieClip("swfHolder",1); //so create a movieclip
nm.loadMovie("myfile.swf"); //and load our .swf file into it
}
}
fileExists.load("myfile.swf") //initiate the test


You can do the same with any file type, even if flash doesnt support the loading of that filetype. You may also be wondering if the above process means you have to load a file twice, the answer is NO. If you are running you flash movie in the browser, then when you check to see if the file exists, the onLoad even handler wont fire until the file has fully downloaded into the browsers cache, but of course the Loadvars object wont do anything with an image file, sound file, or swf file. The next time round, when it comes to actually loading the file to actually display it(swf,image,text) or play it(sound) the file will load almost instantly from the browsers cache. If your flash movie is running on the local machine, then you dont have to worry about loading times anyway, because, as always the loading of a file locally is almost instant.

(Adaugat: 02-18-2004, Accesari: 1, Scor: 3.68, Voturi: 28, Pareri: 8)
Adauga la Favorite Recomanda unui prieten

Pareri: (8)

fileExists=new LoadVars();
fileExits._parent=this;
fileExists.onLoad=function(success)
{
//success is true if the file exists, false if it doesnt
if(success)
{
//the file exists
var nm=this._parent.createEmptyMovieClip("swfHolder",1); //so create a movieclip
nm.loadMovie("myfile.swf"); //and load our .swf file into it
}
}
fileExists.load("myfile.swf") //initiate the test

(Adaugat: 02-27-2007 utilizator: Guest)

Doesn't work...I am trying to make the movie do something if the file doesn't exist....And this doesn't work...!
(Adaugat: 12-02-2006 utilizator: Guest)

how about loading a file extension of [*.mp3] ? Does it still work?
(Adaugat: 08-22-2006 utilizator: Guest)

>> fileExists.load("myfile.swf") //initiate the test

But this is not a test, it is a real loading statement. So it is for big files not the best practice.

(Adaugat: 07-24-2006 utilizator: Guest)

but with for or while, it's return infinite bucle, i trying to know if "pi1.jpg" to "pic10.jpg" exist.
(Adaugat: 03-01-2006 utilizator: Guest)

Ah. But it loads the file from the server twice
(Adaugat: 02-24-2006 utilizator: Guest)

This is detecting the image/no image pretty cool, but I can not make it load anything into the empty MC or to an existing one on the stage. Any ideas why?
(Adaugat: 02-17-2006 utilizator: Guest)

Thanks, this worked great. I needed to write a script that determines if an flv exists on the CD. Works perfectly.
(Adaugat: 10-07-2004 utilizator: Guest)


Adauga opinie
Please note:
We review EVERY comment before it appears on the site, so please dont waste your time by posting spam links :)
No URLs allowed, no HTML please.

If you register or login first, your review will contain your nickname


Voteaza-l



Excelent!
Foarte bun
Bun
Potrivit
Slab