How do I pass UI element names from script through a function?

How do I pass UI element names from a script through a function using AppleScript?
For example:

click button “Save” of sheet 1 of window “Untitled”

In the example above, I need to pass the values “Save”(i.e. button name) and “1”(i.e. sheet name) through a function. It does not seem to work. Is there any way of making this work?

  1. go to this website… http://macscripter.net/
  2. choose “save as” from the file menu
  3. then run the following script and it works
set buttonName to "Save"
set sheetName to 1
set windowName to "Applescript and Scripting Resources @ MacScripter"

tell application "System Events"
	tell process "Safari"
		click button buttonName of sheet sheetName of window windowName
	end tell
end tell