Presentation is loading. Please wait.

Presentation is loading. Please wait.

WML, WMLS More acronyms than you can shake a stick at!

Similar presentations


Presentation on theme: "WML, WMLS More acronyms than you can shake a stick at!"— Presentation transcript:

1 WML, WMLS More acronyms than you can shake a stick at!

2 Overview Fibonacci re-visited WML  More samples  Templates, access control, and comments WMLS  Initialisation control and strings

3 The Fibonacci Sequence The Fibonacci Sequence is a sequence of numbers where each number is the sum of the previous two.  The Fibonacci Sequence was originally devised by a fellow named Fibonacci (surprise) in the 1600’s to model the population growth from a pair of immortal rabbits.  His question was, if every month every pairing of rabbits produced one more rabbit, could he predict how many rabbits he would have after a certain number of months? This research is of key interest to rabbits and French chefs everywhere.  We’ll write Fib(n) for “The number of Fibonacci rabbits in month n”.

4 The Fibonacci Sequence  In the first two months, Fib collected rabits: Fib(1) = 1 Fib(2) = 1  During month three he introduced the two rabbits: Fib(3) = 2 = 1 + 1  In month four, the two produced one more rabbit: Fib(4) = 3 = 2 + 1  In month five, the three produced two more: Fib(5) = 5 = 3 + 2  In month six, the five produced three more: Fib(6) = 8 = 5 + 3

5 The Fibonacci Sequence In general, each month, Fib(month) is equal to Fib(the previous month) plus Fib(the month before that): Fib(1) = 1 Fib(2) = 1 Fib(n) = Fib(n-1) + Fib(n-2) How would you translate this into code? (Rhetorical question. Answer it in the homework, not now.)

6 WML - Combining approaches Let’s look at combining some of what we’ve seen. How would you write a page that let the user choose an image? We’ll need:  An tag to display the picture;  and tags to pick;  some ’s to contain the content;  one to hold them all, and in the bind them.

7 WML <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN" "http://www.wapforum.org/DTD/wml13.dtd"> Today's weather : Sunny Partly cloudy Cloudy Rainy

8 WML How did the user’s choice wind up being shown?  Each time the user clicked an tag, that had an onpick event handler. The onpick reloaded the page.  Because each also had a value attribute, that value was assigned to the tag’s variable.  The tag’s variable, $(name), was the file path we used for the tag.  So each time the user clicked, it changed the value of $(name) and refreshed the card; which changed the value used in the src attribute of the tag; which changed the picture that was being displayed.  An interesting note is that the tag picks its value from the first tag, so we get an image showing up on first load.

9 WML The tag meets the tag:  You can add an tag to an tag to enhance the onpick behavior: Sunny... This is an effective way of dealing with the fact that the onpick attribute only takes a URL.

10 WML - Access control It’s always possible to type in a URL manually.  Wouldn’t it suck if your e-banking web site had a password-check page that forwarded the user to the “transfer your money” page, and the user could just type in the URL for the money-transfer page without checking their password? and  The tag contains info about a document. The tag belongs in a document’s tag.  The tag limits the domain and filepath that the user can come from to get to this tag: (from the documentation at phone.com:) domain - The URL domain of other decks that can access cards in this deck. The default value is the domain of the current deck. path - The URL root of other decks that can access cards in the deck. The default value is "/" (the root path of the current deck) which lets any deck within the specified domain access this deck.

11 WML - Access control Access-control example:... This would define a document which could only be reached by clicking links in documents downloaded from Luton’s web server; you couldn’t link to the document from anyplace else.

12 WML - Comments In WMLScript, comments can be either  // single-line comments, or  /* multi-line comments */ exactly like C++ or Java.  There’s no JavaDoc (tm) in WML. To write comments in WML, use the markers.

13 WML Script for initialisation Last week we saw that you could initialise the value of a variable with the onenterforward event:  This can be problematic if you want to change the value of $(Foo) in another card and then the user clicks forward to the first card again (following a link forward, as opposed to hitting the Prev button to go back.)

14 WML Script for initialisation An example of things going wrong: myVar = $(myVar) Click for second card myVar = $(myVar) Click for first card Here the value of myVar will be changed every time the phone loads card1 or card2. That’s not a bug; it’s a feature. But what if you wanted to preserve the change you made in card2, but still have a valid value coming into card1?

15 WML Script for initialisation One way to fix things would be to add an ‘initialisation’ card at the front of the document: myVar = $(myVar) Click for second card <card id="card2".............. Here the value of myVar will be changed every time the phone loads card2, but only once before it loads card1. So the change made in card2 is preserved.

16 WML Script for initialisation Another solution to the same problem would be to call a WML Script function: myVar =.................. The WML Script can actually test the var: extern function init() { if (!String.compare(WMLBrowser.getVar("myVar"), "")) WMLBrowser.setVar("myVar", "first card (from WMLS)"); WMLBrowser.refresh(); } This way the var is only initialised once.

17 WML Script - Strings A few words about strings in WML Script:  A “String” is a sequence of characters--letters and numbers-- like “bob the string” or “number : 1234” or “!@#%!%”.  The WMLS String Library provides a host of functions to manipulate Strings. String.compare(S1, S2) : Test for equality  compare(s1,s2) will actually test whether two strings are different. So if (compare(s1,s2))... is testing whether s1 != s2.  To test whether s1 equals s2, use !compare(s1,s2).  Remember that comparison is case-sensitive!


Download ppt "WML, WMLS More acronyms than you can shake a stick at!"

Similar presentations


Ads by Google