6.2. Calling a Function Located in a Different WMLScript File

Preferences - Do not show ads

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

Contents at a Glance (Click Here for Full Table of Contents)
Print this Web Page | | Back to Top

Feedback Form (Expand)

What do you think about this web page?

WMLScript Tutorial Table of Contents WMLScript Tutorial Contents at a Glance Preferences - Change Color Scheme Preferences - Do Not Show Ads Previous Page Next Page