Search code examples
actionscript-3flash

AS3 remove extension from var


I believe this is a simple question. How can I remove the ".mp3" extension in the var name?

import flash.filesystem.File;
var desktop:File = File.applicationDirectory.resolvePath("Music");
var files:Array = desktop.getDirectoryListing();
for (var i:uint = 0; i < files.length; i++)
{

 var myVar = files[i].name;// gets file name. 
}


trace(myVar); // comes out "mySong.mp3"

Should I use a split or remove the last 3 characters? What is the best method to do this?


Solution

  • Yeah, I would think split would work best. This way you could use the same method no matter what type of file you are pulling.

    var myVar = files[i].name.split('.')[0];