In this step you add several advanced mobile device-specific features.
To add a button that when clicked dials the number of the selected restaurant, do the following:
Open the file Step3\restaurantFinderStep3.fla, which contains the new telephone button MovieClip on the map screen (frame 5).
To call a specific number add the following code to line 16 of the ActionScript of frame 5 (map screen):
When the user clicks this button a dialogue appears asking if they want to call the specified number.
A mobile device equipped with GPS can help the user locate their exact position on the map along with the location of the restaurant.
Flash Lite applications can access phone-specific functions such as GPS, contacts, and calendars using Platform Services. The Platform Service APIs are supported through a Nokia-proprietary ActionScript 2.0 library and are supported since Flash Lite 3.0 on S60 5th Edition devices. The Nokia XpressMusic 5800 is an ideal S60 5th Edition device equipped with GPS to test such location-aware application.
To use Platform Services on a conventional computer, download and install the ActionScript library. You can find this library with extensive documentation here.
To draw a line between the current location and the location of the restaurant, do the following:
With Platform Services ActionScript library installed, import it into your project by using the following line import com.nokia.lib.Service;
Open Step3\restaurantFinderStep3B.fla. This .fla file contains a new GPS button on the map screen and is used to activate the GPS.
To add functionality to the button, add the following code to the line 1 of the ActionScript on frame 1 (home screen):
The built in security features of the platform asked the user if the application can use the location information when the application is launched.
To add functionality to the GPS button, add the following code to the line 20 of the ActionScript on frame 5 (map screen):
When the user clicks the GPSButton, the location is loaded into the variable outParams (var outParams = location.GetLocation(inParams);).
If the application encounters an error the GPS icon turns red. Use the errorId variable to identify what went wrong. If the error code is 0, the location data was loaded properly.
This service provides a variety of location, position and direction data, but in this application you use only longitude and latitude.
The addressString, which loads the map image, is altered to load a new map when the location is found. This map is still centred on the selected restaurant (center=" +restaurantsData[selectedRestaurant]["latitude"]+","+restaurantsData[selectedRestaurant]["longitude"]) but it also draws a green pin ( latitude+","+longitude+",green). Additionally, to aid navigation, the application draws a line between the two points (path=rgb:0x0000ff,weight:5|" + latitude+","+longitude+"|" +restaurantsData[selectedRestaurant]["latitude"]+","+restaurantsData[selectedRestaurant]["longitude"]).
To make sure that both points are visible on the map, the application scales the map regardless of the distance between them. Google Maps allows scaling by using degrees of longitude and latitude between the edges of the area you want to cover on the map. To do this, the two variables spanHeight and spanWidth are calculated. By taking the difference between the two points (across each axis) and multiplying by 4 (as one point is in the middle of the map multiplying by 4 covers both points and leaves a little extra map visible beyond the two points). These two variables are then added to the addressString (&span="+spanWidth+","+spanHeight).
This feature is currently limited to the restaurant information map. It is not included on the general map, which is accessed from the main menu. If you want to test your understanding of location platform services you can add a GPS button to this screen, which could add a pin to show user's location on the map.
Currently Platform Services cannot be tested in Device Central. Hence, you have to transfer the application to a device to test it. Note also that the GPS feature works only if the device can detect enough satellites.
You can find the completed Step 3 here (download and install the file to your mobile device).
You can find the completed Step 3 .fla source file here.
In order for the application to access both local and network data it must be placed in a trusted folder, created by the user. This involves a few extra steps during the installation the user might not be comfortable with. Additionally, the user must navigate to this folder every time they want to launch the application. The solution for these inconveniences is to create a SIS package that installs the application like a native application and shows the icon in the applications folder.
To package and sign your Flash Lite application as an installable SIS package, use the free Forum Nokia Flash Packaging Tool:
Note that the current Forum Nokia Flash Packaging Tool is a beta release.
To create an SIS package of the application from this hands-on, follow these instructions.