Scope problem

I’m having trouble with what I think is a scope problem. Whenever I run this script, I get an error message telling me that either the variable fromFolder or toFolder isn’t defined. Even though they both get declared as globals in the on awake from nib handler. I know Applescript Studio handles scope differently than plain vanilla Applescripts, but I find it hard to believe it’s impossible to simply declare a global variable

on awake from nib theObject
	global fromFolder
	global toFolder
	set fromFolder to ""
	set toFolder to ""
end awake from nib

on clicked theObject
	if name of theObject = "fromFolderbutton" then
		set fromFolder to choose folder with prompt "Choose Source Folder..."
	else if name of theObject = "toFolderbutton" then
		set toFolder to choose folder with prompt "Choose Destination Folder..."
	end if
	if (fromFolder is not "" and toFolder is not "") then
		addFoldersToList(fromFolder, toFolder)
		set fromFolder to ""
		set toFolder to ""
	end if
end clicked

At least in vanilla (non AppleScript Studio), global variables need to be declared as global either at the top-level or in every handler that uses them. In the sample code below, either the VARIATION A line needs to be uncommented or both the VARIATION B lines need to be uncommented. Having all three lines uncommented is also OK.

global a, b -- VARIATION A

to _set(x, y)
	--global a, b -- VARIATION B
	set a to x
	set b to y
end _set

to _get()
	--global a, b -- VARIATION B
	return {a, b}
end _get

on run
	_set("asdfgh", "qwerty")
	_get()
end run

If there is no top-level global (or property) declaration for a variable name then it is a local variable, even if other handlers declare it as global for themselves.

Thanks, I got confused by the fact that you can declare a global inside a handler and it will persist upwards but not “sideways”.