newbie needing help

I have a script that works perfectly in script editor, but once I tried to port it to x-code and have a button fire the exact same code the repeat statement keeps failing. I can;t even get into the repeat statement.

Can anyone see what I am doing incorrectly?

repeat with myItem in list folder theChosenfolder as alias without invisibles
set myPath to (theFolder as string) & myItem
set myInfo to info for (myPath as alias)

if kind of myInfo is "Folder" then
	doFolder(myPath & ":", theObject)
else if kind of myInfo is not "Alias" then
	set myFolder to (theFolder as string)
	my doFile(myPath, kind of myInfo, myFolder)
end if

end repeat

I don’t know what I was doing at first, but I redid it from scratch and it is now working like a champ.