14. WMLScript Standard Libraries Overview

WMLScript is based on ECMAScript, which is the standardized version of JavaScript. However, some functionality of ECMAScript has been taken away in order to increase the efficiency of WMLScript. To keep WMLScript sufficiently powerful, a number of standard libraries are added to it. Functions in the WMLScript standard libraries can perform tasks that cannot be easily implemented or are impossible to be implemented by writing your own WMLScript code.

There are six standard libraries totally. Here is an overview of them:

1. WMLBrowser library
The WMLBrowser library provides a group of functions to control the WML browser or to get information from it.

2. Dialogs library
The Dialogs library contains functions for displaying alert messages, confirmation messages and input boxes to users.

3. String library
The String library provides a number of functions that help us manipulate strings.

4. Float library
The Float library contains functions that help us perform floating-point arithmetic operations.

5. Lang library
The Lang library provides functions related to the WMLScript language core. It contains functions for generating random numbers, performing some arithmetic operations and dealing with data type conversion.

6. URL library
The URL library contains functions that help us manipulate URLs.

The WMLScript standard libraries are included in the WAP specification. Hence, mobile devices that support WMLScript should also support the WMLScript standard libraries. Note that the Float library is only available on mobile devices that can perform floating-point calculations.

WMLScript programmers should get familiar with the standard libraries. With such knowledge, you can know whether a particular task can be done by using the functions in the standard libraries. If the standard libraries do not have the function you need, that means you have to implement the function yourself or the task cannot be done with the WMLScript language.

14.1. How to Call a Function in the WMLScript Standard Libraries

Calling a function in the WMLScript standard libraries is simple. It is the same as calling your own function, except that you have to add the library name and a dot character before the function name. This is the syntax:

library_name.function_name(parameter1, parameter2...);

The following WMLScript example demonstrates how to call the sqrt() function of the Float standard library to calculate the square root of a number:

function findSquareRoot(number)
  return Float.sqrt(number);

In the following sections, we will introduce to you each of the standard libraries and provide an in depth coverage of the commonly used functions.

Previous Page Page 30 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