Write permission & Resource Utiities

I’m trying to make a script that would extract every sound from an application, and put every sound in a different file. I’m getting a error that tells me that i cannot write to a file.

on open this_file
	set sound_type to "snd "
	repeat with x from 1 to count this_file
		set reference_of_file to res open (item x of this_file)
		set number_of_sounds to res count reference_of_file type sound_type
		tell application "Finder"

			set sound_folder to make new folder at (path to desktop) with properties {name:"sons : " & name of item x of this_file}
			set sound_list to {}

			repeat with y from 1 to number_of_sounds
				set sound_list to sound_list & (make new file at (sound_folder) with properties {name:"son " & y, creator type:"movr", file type:"sfil"})
			end repeat

		end tell
		set reference_for_sound to res open (item x of sound_list) with write permission
		set data_sound to res get reference_of_file type sound_type index y
		res put reference_for_sound type sound_type id 128 data data_sound
		res close reference_for_sound
		res close reference_of_file
	end repeat
end open

Jean-Baptiste LE STANG

I achiebe to make the script works but I don’t know why. can someone explain to me why putting this line “set data_sound to res get reference_of_file type sound_type index y” out of the tell statement my script works?

on open this_file
	set sound_type to "snd "
	repeat with x from 1 to count this_file
		set reference_of_file to res open (item x of this_file)
		set number_of_sounds to res count reference_of_file type sound_type

		tell application "Finder"
			set sound_folder to make new folder at (path to desktop) with properties {name:"sons : " & name of item x of this_file}
		end tell

		set sound_list to {}

		repeat with y from 1 to number_of_sounds

			tell application "Finder"
				set new_file to make new file at (sound_folder) with properties {name:"son " & y, creator type:"sfil", file type:"movr"}
				set sound_list to sound_list & (new_file)
				set reference_for_sound to res open (item y of sound_list) with write permission
			end tell

			set data_sound to res get reference_of_file type sound_type index y

			tell application "Finder"
				res put reference_for_sound type sound_type id 128 data data_sound
				res close reference_for_sound
			end tell

		end repeat

		res close reference_of_file
	end repeat
end open

Jean-Baptiste LE STANG