6.2. Calling a Function Located in a Different WMLScript File

To call a function located in a different WMLScript file, you have to declare that WMLScript file at the very beginning of your code using the "use url" statement, which has the following form:


use url identifying_name "url_of_the_wmlscript_file";


identifying_name is a name you associated to the external WMLScript file. This name will be used to refer to the external WMLScript file.

url_of_the_wmlscript_file is the URL of the external WMLScript file. The URL can be in absolute or relative form.

After you have declared the external WMLScript file, you can call a function located in that file by:


identifying_name#function_name(argument1, argument2...)


Now let's see an example that can help you understand what we are talking about better. Let's say the wmlscript_1.wmls file contains the following function wmlscript_function():


extern function wmlscript_function()
{
  return "Welcome to our WMLScript tutorial";
}


Now we want to call wmlscript_function() in the main_function() function of another WMLScript file (wmlscript_2.wmls) that is located in the same directory as wmlscript_1.wmls. To do this, we can write something like this:


use url Script1 "wmlscript_1.wmls";

function main_function()
{
...
  wmlscript_variable = Script1#wmlscript_function();
...
}


Since both files wmlscript_1.wmls and wmlscript_2.wmls are located in the same directory, we just need to use the file name as the URL in the "use url" statement.

Notice that the function definition of wmlscript_function() starts with the extern keyword. The extern keyword is required here. It specifies that wmlscript_function() is allowed to be called from outside wmlscript_1.wmls.


Previous Page Page 9 of 71 Next Page


Feedback Form (ExpandCollapse)

What do you think about this web page?






(Optional) Please provide us more details. For example, suppose you select option 2 above, can you tell us specifically what information is missing? You can also suggest anything that can help us improve this web page.

(Optional) Your name:

(Optional) Your email address:

Please enter again to confirm:

Due to the amount of messages we received, we may not be able to reply to all messages.

A button for going back to the top of this page