What Marcel points out is actually a
dynamic global variable.
It persists beyond the execution of the method, but it's scope is global.
To achieve a true form-level variable you could use the "this" keyword.
In a form method, assigning a variable to "this" will actually bind the object to the form. But be cautious, there are other objects bound the for that you might not want to overwrite, such as the controller and data-providers.
Here's an example:
- Code: Select all
// local variable - it lives and dies in the method
var localVar= "local";
// form level variable - binds object to form
this.formVar= "form";
// dynamic global variable - dynamically creates a global variable, lives on after method terminates
dynamicGlobalVar = "global";
A subtle caveat is the precedence when referencing the variables.
The order is local, then form, then global.
...meaning that if you've defined variables of the same name, but at differing scopes, the local one will take precedence.
Example:
- Code: Select all
// create dynamic global
theVar = "global";
// create form-level
this.theVar = "form";
// create the local scope
var theVar = "local";
// print out theVar
application.output(theVar); // it prints the local var
// you have to explicitly cite the scope if you want the form level
application.output(this.theVar);
Hope this helps,
Sean