After the WML file passes one or more parameters or variables to a WMLScript, it is up to the script to process the parameters or variables. The steps required to process a parameter or variable passed from a WML file to a WMLScript function are:
Use WMLBrowser.getVar to access the variable value. Parameter values are accessible without this step.
Take action based on the value of the parameters and/or variables.
The first step in processing a variable passed from a WML file is to retrieve the variable's value from the browser. The WMLBrowser library getVar function makes this a simple matter. You can use getVar in the body of a function or you can use it to initialize the external function's variable(s).
For example, using getVar in the body of a function:
action = WMLBrowser.getVar("action");
An example of using getVar to initialize the external function's variables:
extern function myfunction(cardURL)
{
var state = WMLBrowser.getVar("state");
var action = WMLBrowser.getVar("action");
var image = WMLBrowser.getVar("image");
... //function implementation
}
Now that the external function has retrieved the value of the parameters or variables the WML file passed to it, the script must act upon the values it received. Examples of actions include modifying the value of the parameter and returning it to the UP.Browser, setting text or image variables that the script then returns to the UP.Browser, advancing to the next card in the deck of the WML file that called the function, or calling a different WML file. The possibilities are nearly limitless.
For example:
extern function myfunction(cardURL)
{
var state = WMLBrowser.getVar("state");
var action = WMLBrowser.getVar("action");
var image = WMLBrowser.getVar("image");
var nexturl;
if (action == "reset") {
//set the value of the variable "image" to a BMP file
WMLBrowser.setVar("image", "newimage.bmp");
}
if (action == "nextpage") {
nexturl = cardURL + "pagetwo.wml"; //build URL string
//load a WML file at the relative location passed
//in as a parameter to myfunction
WMLBrowser.go(nexturl);
}
if (action == "newdeck" {
var card = "http://www.host.com/loc/app.dck#start";
//load card "start" from the deck at the new full URL
WMLBrowser.go(card);
}
}