User Guide

28 Tutorial: Creating a Flash Lite Application (Flash Professional Only)
When the user selects the Reservations option, the onPress handler
dials the phone number specified in the
location_so shared object.
(Later in this procedure, you’ll create code to create the shared object.)
If the user hasnt yet specified a location to call for reservations, the
application sends the playback head to the frame labeled “options”,
where the user selects their preferred location for making reservations.
12. Now add the following code to create a key listener for the left and right
soft keys:
Key.removeListener(myListener);
var myListener:Object = new Object();
myListener.onKeyDown = function() {
var keyCode = Key.getCode();
if (keyCode == ExtendedKey.SOFT1) {
// Handle left soft key event:
gotoAndStop("options");
} else if (keyCode == ExtendedKey.SOFT2) {
// Handle right soft key event:
fscommand2("Quit");
}
};
Key.addListener(myListener);
This code uses a key listener object to handle right and left soft key
events. When the user presses the left soft key, the playback head is sent
to the frame labeled “options, and the right soft key closes the
application.
For more information about using event listeners, see “Using a key
listener to handle keypress events (Flash Professional only)” in
Developing Flash Lite 2.x Applications.
13. Lastly, add code to initialize the shared object that saves the user’s
preferred location for making reservations:
// Define Shared Object listener function:
function so_listener (the_so:SharedObject) {
if (the_so.getSize () == 0) {
// The shared object doesn't exist, so the user
// hasn't set a preference yet.
}
the_so.removeListener ("location");
}
// Create shared object:
location_so = SharedObject.getLocal ("location");
// Add SharedObject listener object:
SharedObject.addListener ("location", this,
"so_listener");