No globals in AS-S?

I just read a discussion on the lack of support of global variables in AS-S. Is this true? I am about to clean up my code by switching to globals in some cases. I tries the first one, and it did not work.

I want to set a variable to a text view and set it as a global so I don’t have to keep referencing it. Is that not possible?

Thanks!
Doug

Would you post the code you’re trying to use?

Sure.

It looks like this:

global sourceText

set sourceText to text view "textView" of scroll view "scrollView" of window "main"

on clicked theObject
	if the name of theObject is "buttonA" then
		set contents of sourceText to "Hello World."
	else if the name of theObject is "buttonB" then
		set contents of sourceText to "Hello World."
	end if
end clicked

That is the simplest script I tried without success.

Thanks.

The short answer is that sourceText never gets set.

AS Studio is based on handlers/events; You don’t just put code into a script file. You should try setting sourceText in either the will finish launching or launched handler (see “File’s Owner” in IB).

Got it, Bruce. I just checked the code of one of the Examples (Drag Race) and saw what you mean.

Thanks for the direction.

Doug.