Scripting Objects in AppleScript

The way I have it is obviously the wrong way to do it, but how do I get a variable stored in an object into another variable, and/or display it in a dialog? Below I have posted the code that is wrong and does not work. I figure that it will clear up anything about my question that is hard to understand.


script anItem
	property MEM1 : text
	
	on setMEM1 to var
		set MEM1 to var as text
		
		return ""
	end setMEM1
	
	on getMem1 to Xvar
		
		return MEM1
	end getMem1
	
	
end script

on run
	
	tell anItem to setMEM1 to "debug"
	set theNum to 5
	set aVar to (tell anItem to getMem1 to "")
	display dialog aVar as text
	
end run

You can use either of the following:

tell anItem to setMEM1 to "debug"
set aVar to (getMem1 to "") of anItem
set aVar to anItem's (getMem1 to "")

Or you can get/set the variable directly without using the getters/setters:

set anitem's mem1 to "debug"
set aVar to anItem's MEM1

Also, you’re setting the initial value of mem1 in an unusual manner. Your initial value of text is actually a class, not a value with the class of text. You could use “text” with quotes around it to give ti the value of text. Normally though I would use missing value which means it hasn’t been set yet.