The Essential Guide to HTML5

(Greg DeLong) #1

CHAPTER 7


Creating the second maze application


The localStorage data can be accessed by a different application from the one that created the data, as
long as it is on the same server. This is a security feature, as mentioned previously, restricting readers of
local storage to scripts on the same server.

The second script is based on this feature. Table 7-4 shows the functions calling or being called; it is a
subset of the previous one.

Table 7-4. Functions in the Travel Maze Script

Function Invoked By / Called By Calls

init Invoked by action of onLoad in body tag drawall

drawall Init
startwall
stretchwall
getkeyAndMove
getwalls

draw method for Walls and for
token: drawtoken and
drawAline

Token var statement declaring mypent

Wall startwall

drawtoken drawall using draw method for the token object in
the everything array

movetoken getkeyAndMove using the moveit method for
mypent

intersect

drawAline drawall using draw method for Wall objects in the
everything array

getkeyAndMove (^) Invoked by action of an addEventListener call in
init
movetoken using the moveit
method for mypent
getwalls (^) Invoked by action of onSubmit for the gf form drawall
The functions are exactly the same as in the all-in-one script with one exception, the getwalls function,
so Ive only commented the new or changed code. This application also has radio buttons in place of the
form input fields. Table 7-5 shows the complete code for the travelmaze application.

Free download pdf