How are you using your open handler, Emma?
A script that contains an open handler is usually intended to be saved as an application. The presence of the open handler will actually cause it to to be saved as a droplet. Whenever you drag items to the droplet in Finder, the item[s] dropped will be passed to the open handler, as a list of alias[es], for processing.
The choose file (or choose folder) command also returns an alias of the item chosen - and, from your test above, it’s clear that Finder on your machine still knows how to get the name of an alias (as, indeed, it should).
We can also use choose file to test your open handler - by presenting it with an alias (in a single-item list):
on open docList
set x to 1
repeat number of items in docList times
tell application "Finder"
set theFile to item x of docList
set theName to name of theFile
display dialog "NAME:" & return & theName (* test only *)
end tell
set x to x + 1 (* assumed as part of the original script, to increment the value of x *)
end repeat
end open
open {choose file} (* this will pass an alias, as a single-item list, to the open handler *)
Of course, if the handler receives a list of unexpected items (such as strings, for example), an error will occur:
on open docList
set x to 1
repeat number of items in docList times
tell application "Finder"
set theFile to item x of docList
set theName to name of theFile
display dialog "NAME:" & return & theName (* test only *)
end tell
set x to x + 1 (* assumed as part of the original script, to increment the value of x *)
end repeat
end open
open {"some file name or path"} (* this will fail because the list does not contain aliases *)
--> error number -1728 [errAENoSuchObject]: Can't get name of "some file name or path".
Incidentally, you might like to try an alternative to the set x/increment x approach - since AppleScript provides a slightly simpler method when using repeat loops. Here’s an example:
on open docList
repeat with x from 1 to count docList
tell application "Finder"
set theFile to item x of docList
set theName to name of theFile
display dialog "NAME:" & return & theName (* test only *)
end tell
end repeat
end open
Hope that helps.