figuring out file extensions in AS3
I’m currently in the middle of building quite a large content management system in AS3, and I’ve come to the part of working in a decent file manager - so far it can upload, rename, delete and preview (only images) at this moment, but I need to add other things - a downloader, and a thumbnailer, which I’ve spent the last two days doing, anyway - I was looking into how to improve the preview system I have in place… it would be nice for the system to automatically detect what kind of file I’m looking at and decide what the correct way to preview it would be. To do this I need to have flash look at the extension each file has and take it from there - anyway here a little bit of code that’ll remove the extension…
function extractFileType(file:String):String {
var extensionIndex:Number = file.lastIndexOf(".");
if (extensionIndex == -1) {
//No extension
return "";
} else {
return file.substr(extensionIndex + 1,file.length);
}
}
trace(extractFileType("file.jpeg");
And here’s a sneak peek of the thumbnailer - apologies about the photograph
- I’ve there’s enough demand I might clean the code up a bit and release it on here…
And here is a glimpse of the editor and file manager - It’s so beta I haven’t even got round to labeling the buttons!



