Global variables and "on adding folder items to"

Hi there.

I’m currently working on a folder action script and I’m having problems with global variables - they don’t work.
The structure of my script would be something like:

global anyVar

on adding folder items to thisFolder after receiving addedItems
	set anyVar to ((path to desktop as text) & "folder:file")
	-- here's a bunch of code
	subFunction()
end adding folder items to


on subFunction()
	display dialog anyVar
end subFunction

I’m guessing it’s because the script starts right into the “on adding folder items to” function, and doesn’t realize that I’d like some global var’s first.
If I define a var as global inside of the “on adding folder items to”, it doesn’t work either.

Any help on this subject?

Thanks guys.

The posted code just works fine as a folder action on my Mac…

Model: PowerBook G4 1.33 GHz
Browser: Safari 525.20.1
Operating System: Mac OS X (10.5)

It works for me. Are you sure that folder actions are enabled? Try putting a display dialog in the body:

global anyVar
on adding folder items to thisFolder after receiving addedItems
	set anyVar to ((path to desktop as text) & "folder:file")
	display dialog anyVar
	-- here's a bunch of code
	subFunction()
end adding folder items to
on subFunction()
	display dialog "anyVar is: " & anyVar
end subFunction

It seems to work for me now as well. I guess I had some other troubles somewhere in my script (it’s quite large, I just set up an example with what I was trying to do).
Thanks anyways and sorry for this useless thread.