July 24, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

WML Scripting Tips and Integration with PHP

  • August 19, 2002
  • By Steve Schafer
  • Send Email »
  • More Articles »

This series of articles describes how to provide Web content to mobile devices through WML (Wireless Markup Language). This article covers some additional uses for WMLScript and how to integrate PHP with WML. Future articles will cover more advanced PHP and WML techniques.

Note: These articles cover WML and WMLScript version 1.1, which are supported by the majority of mobile devices in use today. The articles assume a working knowledge of HTML and general Web technologies, and further assume that you have read the previous article(s) in this series.

WMLScripting

In the last article we discussed how to use WMLScript to perform basic scripting tasks within your WML pages. As mentioned in that article, WMLScript can be used to validate input and perform basic operations on WML variables. WMLScript can also be used to control the display of various cards and the information contained on them. For example, the following code will display an animation by changing an image's source and refreshing a card every two seconds:

animation.wml

<wml>
  <card id="card1">
    <onevent type="onenterforward">
      <refresh>
      <setvar name="num" value="1" />
      <setvar name="image" value="image1.wbmp" />
      </refresh>
    </onevent>
    <onevent type="ontimer">
      <go href="junk.wmls#main()" />
    </onevent>
    <timer value="20" />
    <p><img alt="$(image)" src="$(image)" /></p>
  </card>

  <card id="card2">
  <p>Animation Done!</p>
  </card>
</wml>

animation.wmls

extern function main() {
var Num = WMLBrowser.getVar("num");
var Image = "";

if (Num < 9) {
  Num++;
  Image = "image" + Num + ".wbmp";
  WMLBrowser.setVar("num", Num);
  WMLBrowser.setVar("image", Image);
  WMLBrowser.refresh();
} else {
  WMLBrowser.go("animation.wml#card2");
  }
}

The deck (animation.wml) sets two variables and forces a refresh. These are the variables:

num:The number to append to the image source
image:  The starting image source (image1.wbmp)

Every two seconds, the main() function in animation.wmls is called. This function adds one to "num," creates a new image source (image<num>.wbmp), and refreshes the card, which causes the new image to be displayed. After the ninth image (image9.wbmp) is displayed, the script goes to the second card in the deck, ending the animation.

Note: The above example assumes that your animation consists of nine images that, when displayed sequentially, create the animation.

WMLScripting is flexible and brings basic scripting to WML. However, it's possible to lend more programming power to WML by infusing it with PHP, as covered in the next section.





Page 1 of 3



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel