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 |
- 1. WMLScript Introduction
- 2. Hello World WMLScript Example
- 3. Compiling WMLScript Code
- 4. WMLScript Language Rules
- 5. Defining WMLScript Functions
- 6. Calling WMLScript Functions
- 7. WMLScript Variables
- 8. WMLScript Data Types
- 9. WMLScript Variables Vs WML Variables
- 10. Passing Arguments to Functions By Value and By Reference
- 11. WMLScript Operators
- 12. WMLScript Conditional Statements
- 13. WMLScript Looping Statements
- 14. WMLScript Standard Libraries Overview
- 15. WMLScript WMLBrowser Standard Library
- 16. WMLScript Dialogs Standard Library
- 17. WMLScript String Standard Library
- 18. WMLScript Float Standard Library
- 19. WMLScript Lang Standard Library
- 20. WMLScript URL Standard Library
- 21. WMLScript Example: Validating Form Data