Here’s an easy way to parse out the file extension of any file in Flex/Flash using AS3.

var filename:String = “document.jpg”;
var nameParts:Array = filename.split(“.”);

var extensionless:String = nameParts[0];
trace (“The filename is ” + extensionless);

var extension:String = nameParts[1];
trace (“The file extension is ” + extension);

3 comments so far

Add Your Comment
  1. This solution doesn’t work with filenames containing more then one ‘.’ characters. Here is a solution adapted from the above example:

    var filename:String = ‘document.a.b.c.jpg’;
    var nameParts:Array = filename.split(‘.’);
    var extension:String = nameParts[nameParts.length-1];
    trace (‘The file extension is ‘ + extension);
    var extensionless:String = nameParts.join(‘.’);
    trace (‘The filename is ‘ + extensionless);

    Kind regards,


    • Awesome! Though i don’t recommend having more than one ‘.’ character in a filename anyways 😛

  2. Hiya! Quick question that’s entirely off topic. Do you know how to make your site mobile friendly? My blog looks weird when browsing from my apple iphone. I’m trying to find a theme or plugin that might be able to fix this problem. If you have any suggestions, please share. Many thanks!