PDA

View Full Version : Reading files out of a directory



doublemazaa
June 25th, 2008, 09:58 PM
Is there a way in AS2 or AS3 to have a swf display and load all the files in a directory, regardless of name?

I've got an swf that's currently loading other swfs through info in an XML file, but I'd like it more if I could just drop all those files in a directory and have the swf load them in regardless of what they're named.

Is this possible? Can anyone point me in the right direction?

Thanks!

John

McGuffin
June 25th, 2008, 10:03 PM
You need to use a server-side language, such as PHP (http://ca.php.net/readdir), and then load the file names into Flash by passing variables. This is, of course, assuming you're reading from a webserver, not a local computer (which can't be done in Flash, but can be done in AIR).

sekasi
June 25th, 2008, 10:20 PM
(the f-ugly solution is to name your files in sequence. 1.swf, 2.swf etc)

but again, that is really .. really ugly ;)

Anogar
June 25th, 2008, 11:32 PM
Yeah.. I had a project on a server where I had no access to server-side scripting, and like 500+ screenshots that needed to be displayed. I was mortified. Anyhow, yeah, I ended up using the ugly solution of naming them sequentially and then listening for a load error to figure out where the end of the project is.

Of course, that means that if item #178 has an error, you'll skip the other 300 of them, but if you want you can only stop after two successive errors but then.. ugh. It's just a mess without serverside scripting.

Sometimes it's the only solution. :-/

edit:

Oh, one more thing to keep in mind is that if you end up going with this brute force attempt - you'll want to consider reversing the array and making it so that the LAST item is displayed FIRST - otherwise when your client says, "Hey, I have 10 new screenshots and I want them highlighted at the front of the application" you'll have to rename the entire rest of the stack, which is horribly inefficient.

Insane au
June 26th, 2008, 03:35 AM
Couldn't you put a list of all the files in an XML file and just read from that? or do you have no access to the server at all?

doublemazaa
June 26th, 2008, 12:44 PM
Couldn't you put a list of all the files in an XML file and just read from that? or do you have no access to the server at all?

I'm doing that already, but I want to be able to read in whatever files are in the directory. That way if I want to add a file to my list, I can just drop it in rather than have to edit an XML file.

Thanks for everyone's help. The server this will be running on is my department's webserver which we pretty much have free range over, so getting this going with PHP shouldn't be any issue. I wish AS3 had a way to do this within itself, but I should be able to get this going now.

Thanks!

John

Anogar
June 26th, 2008, 01:17 PM
Couldn't you put a list of all the files in an XML file and just read from that? or do you have no access to the server at all?

Maintaining several hundred files listen in an XML file is a terrible solution. It just scales very badly, since it requires a ton of maintenance and your XML file will be huge.