I am trying to create one instance of a common script. I would like to use this script to save a few variables and states across the lifetime of the app. However, I am encountering a problem with scope to save these variables and states. The following is an example of how I created this script...
Function Utils() as Object
obj = {
exampleFunction: exampleFunction,
getExampleValue: getExampleValue
}
return obj
end Function
Function exampleFunction()
m.exampleParam = "value of param"
m.exampleObject = {color: "red"}
end Function
[size=85][font=monospace]Function [size=85][font=monospace]getExampleValue[/font][/size]() as String
[/font][/size] if [size=85][font=monospace]m.[/font][/size][size=85][font=monospace][font=monospace]exampleParam <> invalid
return [size=85][font=monospace]m.[/font][/size][size=85][font=monospace][font=monospace]exampleParam [/font][/font]
else
return "invalid"
end if[/size][/font][/font][/size]
end Function
Then when I make the following reference to the Utils script, I expect to get something other than invalid as the value of m.exampleParam
utilsInstance = Utils
utilsInstance.exampleFunction()
?"The value of the example Param is: "; utilsInstance.getExampleValue() 'this returns "invalid", but I was expecting the value set in the exampleFunction() method.
I think the problem is that the "m." object scoping reference within the exampleFunction() refers to the Utils associative array, not the global scope of the app.
How do I ensure the Utils() script can refer to the global scope of the app?