song searcher help

ok, so i have code that when you click a button it prompts you to type a song name. If there is more than one result a list comes up. If ther is no results the dialog comes up telling you there was zero results. I want to change the first prompt so instead of a prompt it’s the contents of a text field (so when the user hits the search button it searches for and plays whatever they type. here is my old code. I still want a dialog to come up saying there is no results. Here is the code

on clicked theObject
if the name of theObject is equal to "title_search" then
		set repeat_num to 0 as integer
		repeat
			set repeat_num to repeat_num + 1
			if repeat_num is 1 then
				set dialog_text to "Type the title of the song that you want to play."
			else
				set dialog_text to "Your search turned up 0 results. Try again?"
			end if
			repeat
				set the_dialog to (display dialog dialog_text default answer ¬
					the_song buttons {"Search", "Cancel"} default button 1)
				set the_song to the text returned of the the_dialog
				if the_song is not "" then exit repeat
			end repeat
			tell application "iTunes"
				set fi_value to fixed indexing
				set fixed indexing to true
				set the matching_tracks to (every track of library playlist 1 whose name contains the_song) as list
				
				--if there's only one match, it is played
				if the (count of matching_tracks) is 1 then
					set my_track to item 1 of matching_tracks
					exit repeat
					
					--if there are more than one matches...
				else if the (count of matching_tracks) > 1 then
					
					--creates a variable containing info about each matching track
					repeat with i from 1 to the (count of matching_tracks)
						set track_name to the name of item i of matching_tracks
						if the artist of item i of matching_tracks is not "" then
							set track_artist to the artist of item i of matching_tracks
						else
							set track_artist to "Unknown"
						end if
						if the album of item i of matching_tracks is not "" then
							set track_album to the album of item i of matching_tracks
						else
							set track_album to "Unknown"
						end if
						set track_info to i & ". " & track_artist & " - " & track_name & " (" & track_album & ")" as string
						if i is 1 then
							set matching_track_display to (track_info) as list
						else
							set matching_track_display to matching_track_display & track_info
						end if
					end repeat
					
					--allows user to choose which matching track to play
					set the_track to {choose from list matching_track_display with prompt ¬
						"Your search turned up " & number of items in matching_tracks & " results. Please specify which track you want to play."} as string
					if the result is "false" then
						set fixed indexing to fi_value
						return
					end if
					
					--finds which track to play
					set ascii_bounds to {48, 49, 50, 51, 52, 53, 54, 55, 56, 57} as list
					set the_number to ""
					repeat until the (ASCII number of the first character of the_track) is not in ascii_bounds
						set the_number to the_number & character 1 of the_track
						set the_track to (characters 2 thru -1 of the_track as string)
					end repeat
					set my_track to item the_number of matching_tracks
					exit repeat
				end if
			end tell
		end repeat
		tell application "iTunes"
			play my_track
			set fixed indexing to fi_value
		end tell
		tell application "Finder" to set the visible of every process whose name is "iTunes" to false

I’ve cleaned up your code a bit. Notice how I handle the changing of the input dialogs. I didn’t need that last line to hide iTunes on my system (Mac OS X 10.4) since it never activates, so I commented it out. Please say if you actually need it.

set songTitle to text returned of (display dialog "Type the song title that you want iTunes to play." default answer "" buttons {"Cancel", "Search"} default button 2)
repeat
	tell application "iTunes"
		set fixedIndexing to fixed indexing
		set fixed indexing to true
		
		set tracksFound to every track of first library playlist whose name contains songTitle
		set foundCount to count of tracksFound
		
		if foundCount is 1 then
			set playTrack to beginning of tracksFound
			exit repeat
		else if foundCount is not 0 then -- greater than 1	
			set tracksList to {}
			repeat with thisTrack in tracksFound
				set trackName to name of thisTrack
				tell artist of thisTrack to if it is "" then
					set trackArtist to "Unknown"
				else
					set trackArtist to it
				end if
				tell album of thisTrack to if it is "" then
					set trackAlbum to "Unknown"
				else
					set trackAlbum to it
				end if
				set trackInfo to trackName & " - " & trackArtist & " (" & trackAlbum & ")" as string
				set tracksList to tracksList & trackInfo
			end repeat
			
			set trackChosen to choose from list tracksList with prompt ¬
				"Your search turned up " & foundCount & " results. Please specify which track you want to play."
			if trackChosen is false then
				set fixed indexing to fixedIndexing
				return
			end if
			
			set my text item delimiters to return
			set tracksList to tracksList as Unicode text
			set my text item delimiters to beginning of trackChosen
			set trackNumber to count of paragraphs of first text item of tracksList
			set my text item delimiters to ""
			
			set playTrack to item trackNumber of tracksFound
			exit repeat
		end if
	end tell
	set songTitle to text returned of (display dialog "No songs with that title were found." & return & return & "Type the song title that you want iTunes to play." default answer "" buttons {"Cancel", "Search"} default button 2)
end repeat

tell application "iTunes"
	play playTrack
	set fixed indexing to fixedIndexing
end tell
--tell application "System Events" to set visible of first process whose name is "iTunes" to false

Now, if you want to use a text field (which I think is a good idea), then you need to give both your window and the text field a name, and do something like this:

on clicked theObject
	set objectName to name of theObject
	
	if objectName is "title_search" then
		set mainWindow to window "main"
		-- OR
		-- set mainWindow to window of theObject
		
		set songTitle to content of text field "song title" of mainWindow
		
		-- Find and play song.
		
	end if
end clicked