How to return the name of a sound file?

I just figured out how to load sounds in Applescript Studio, but I’m having some problems:

First, I’d like to be able to display the name of the sound file that I’ve selected, but it doesn’t seem to be easy to do. If I use the following code:

on clicked theObject
if name of theObject = "select_sound" then
		set the_sound to load sound (choose file with prompt "Pick a sound:")
		set contents of text field "sound_name" of window "window" to interval_sound
		play interval_sound
	end if
end clicked

Then it gives me some gibberish like {NS Sound # 23534} or something like that as the name of the sound. I tried some versions of “path to” … “as string” but I couldn’t seem to get it right. Any ideas?

Secondly, the URL above discusses the need to “free” sounds that have been loaded when changing sounds, but the example seems difficult and confusing. Anyone know a simple way that I could adjust the above code so that it would free any loaded sound (if there was one) before loading a new one?

Third, rather than having the user navigate to the system folder, then to the sounds folder, is there any way I could simply provide a list of sounds in the sounds folder for them to choose from?


There is some information about working with sound names here but I don’t really understand the documentation, and there are no usable examples that I can find. Anyone able to make sense of this?