Category Archives: Flash Lite

Forum Nokia Wiki: Contributor of the Month – March/2010

I wrote Flash Lite related articles and code examples to Forum Nokia Wiki and the Wiki Administrators selected me  to Contributor of the Month.  It is big honor to me - thanks! My articles covers features of APIBridge and S60 Platform Services API for Flash Lite.

"Forum Nokia honors one member every month for their outstanding contribution to our community’s Wiki. The contributor of the month is awarded a new S60 device. The honor is given to people that have contributed outstanding work for the month in number of articles and quality of the articles."

Articles and Flash Lite source codes:
* Capturing and uploading image, video or audio files to server with Flash Lite and APIBridge
* Creating Image Gallery with Flash Lite and APIBridge
* Display contact information and locations in Google Maps with Flash Lite 3.1

Forum Nokia tutorials for Flash Lite

Forum Nokia published a series of Flash Lite tutorials with source codes: Music, LBS, RSS, Social Networking, Photostream, Event and Video.

"These tutorials provide working code for key aspects of Flash Lite integration with the latest S60 devices from Nokia. Each tutorial includes the Flash project, skinned swf files that can be run on an S60 5th Edition device and a tutorial guide document. Several of the tutorials illustrate the packaging of Flash Lite content into a WRT widget."

Display contact informations and locations in Google Maps with Flash Lite 3.1

I improved my eariler example which loads contact informations from users device - displays informations to scrollable list and shows contacts location in Google Maps (static image). In this new version a new Device Object is used to keep Flash Lite application in portrait mode all the time. Another great feature is to detect users device location with APIBridge. In this version of Contacts Demo both user location and contact's address location is shown at static Google Maps Image (user can adjust zoom level).

This Flash Lite example code article is published in Forum Nokia Wiki. You can found more informations and source codes there:
- Display contact informations and locations in google Maps with Flash Lite 3.1

Edit: This tutorial got Featured Article of the Week status in Forum Nokia Wiki at Week 14 - April 4th, 2010.

Creating Image Gallery with Flash Lite and APIBridge

In this my second Forum Nokia Wiki code example article I explain how to create a image gallery with Flash Lite and APIBridge. Technically first all the images data are loaded from device using the Media Management Service, then user can browse images just pressing next or prev buttons on the screen. Device object is used to keep Flash Lite application in landscape mode all the time.

APIBridge and Platform Services API provides great plug-ins for Flash Lite Developers, if you are not familiar with those, you should give some time to them.

Capturing and uploading image, video or audio files to server with Flash Lite and APIBridge

Finally I got time to write my first article in to forum nokia wiki. APIBridge has been there for a while for Flash Lite and JavaScript developers. In my first article I will demonstrate how to capture image, video or audio in Flash Lite 3.0 based devices and how to send those files to server side. This can be done with Flash Lite and ActionScript 2.0 in a few lines of code. You can find FLA and PHP source codes at the bottom of article page in forum nokia wiki.

Here is a direct link to wiki page.

Edit: This tutorial got Featured Article of the Week status in Forum Nokia Wiki at Week 11- March 14th, 2010.

New Flash Lite Components from Forum Nokia

Forum Nokia released new Flash Lite Components set a few days ago. The resource file contains four UI components (Button, List, Popup and ScrollBar), two data components (Contacts and Media), source files and lots of documentation. Installation of components is very easy, just download set from Forum Nokia, unzip it and browse "All Components.mxp" file in your computer and double click it. Adobe Extension Manager starts and installs all components to your Flash IDE. In Flash you can find components in Forum Nokia section of Components Panel and just drag and drop to your application.

I modified Nokia Forum's MyContacts demo to load Image names from my device to List Component. Image is show with MovieClip object when user clicks image name from List Component. I think these components are working really nicely and this is one good way to get organized components to the Flash Lite world!

Media Demo scr 1 Media Demo scr 1 Media Demo scr 1

Sources:
- PTMImagesDemo.zip (tested in 5800)

Links:
- Nokia Forum: Flash Lite Components
- Nokia Forum: Flash Lite Components Documentation
- Ready Made Components to Speed up Mobile Flash Development (win a Nokia N97)

Contacts Demo – S60 Platform Services API example with Flash Lite

Here is my first Nokia S60 Platform Services API test with Adobe Flash Lite. This demo is designed to run 360x640 screens (like Nokia 5800 and N97). Application first loads contacts name, phone number, work and home addresses and shows all informations nicely in interactive scrollable menu.

Contacts Demo scr 1 Contacts Demo scr 2

  1.  
  2. // create contacts service object
  3. var contact = new Service("Service.Contact","IDataSource");
  4. var inParams = {Type:"Contact"};
  5. // get contacts from phone
  6. var outParams = contact.GetList(inParams);
  7. if (outParams.ErrorCode == 0) {
  8. var outList = outParams.ReturnValue;
  9. var outputEntry = null;
  10. var i:Number = 0;
  11. var step:Number = 40;
  12. do {
  13. outputEntry = outList.next();
  14. if (null != outputEntry) {
  15. // add a new contact to container list
  16. i++;
  17. var mc:MovieClip = container_mc.attachMovie("ContactItem","Contact"+i,
  18. container_mc.getNextHighestDepth());
  19. container_mc.addMC(mc);
  20. container_mc["Contact"+i].init(outputEntry, container_mc, i,
  21. contactheader_fmt, contactdata_fmt);
  22. container_mc["Contact"+i]._y = (i-1)*step;
  23. } else { break; }
  24. } while (true);
  25. // show contact list
  26. gotoAndStop("show");
  27. } else {
  28. info_txt.text = outParams.ErrorCode;
  29. }

Details of contact information are displayed when user presses contacts name. Multiple contacts can be open at the same time. If contact has work or home address, this demo applications can load static JPG from Google Maps to show address in a map.

Contacts Demo scr 2 Contacts Demo scr 3

  1.  
  2. // data objects to server and back
  3. var sendDataLV:LoadVars;
  4. var loadDataLV:LoadVars;
  5. // show map loading info to user
  6. var info_mc:MovieClip;
  7.  
  8. //start loading request
  9. function showInMap(street:String,city:String,country:String):Void {
  10. sendDataLV = new LoadVars();
  11. loadDataLV = new LoadVars();
  12. info_mc = _level0.attachMovie("info","info_mc",
  13. _level0.getNextHighestDepth());
  14. info_mc._x = 5;
  15. info_mc._y = 70;
  16. loadDataLV.onLoad = latLonLoaded;
  17. sendDataLV.address = street+" "+city+" "+country;
  18. _level0.info_mc.text_txt.text += "street : " + street + "\n";
  19. _level0.info_mc.text_txt.text += "city : " + city + "\n";
  20. _level0.info_mc.text_txt.text += "country : " + country + "\n";
  21. // send lat and lng request to server
  22. sendDataLV.sendAndLoad(phpUrl,loadDataLV,"POST")
  23. _level0.info_mc.text_txt.text += "Get lat and lng...\n";
  24. back_mc._visible = true;
  25. }
  26.  
  27. // lat and lng returned from server
  28. function latLonLoaded(ok:Boolean):Void {
  29. if (ok) {
  30. if (loadDataLV.latitude != undefined &&
  31. loadDataLV.longitude != undefined) loadMap();
  32. else _level0.info_mc.text_txt.text += "No Lat and Lng!\n";
  33. } else {
  34. loadDataLV = null;
  35. sendDataLV = null;
  36. _level0.info_mc.text_txt.text += "Can't connect server to get Lat and Lng!\n";
  37. }
  38. }
  39.  
  40. // start loading map from Google
  41. function loadMap():Void {
  42. // show info
  43. _level0.info_mc.text_txt.text += "Loading map...\n";
  44. _level0.info_mc.text_txt.text += "Latitude: "+loadDataLV.latitude+"\n";
  45. _level0.info_mc.text_txt.text += "Longitude: "+loadDataLV.longitude+"\n";
  46. // map size
  47. var mapWidth = 350;
  48. var mapHeight = 520;
  49. // lat and lng
  50. var lat = loadDataLV.latitude;
  51. var lng = loadDataLV.longitude;
  52. var apiKey = 'API_KEY';
  53. // JPG loader
  54. var loader:MovieClipLoader = new MovieClipLoader();
  55. // url
  56. var mapUrl:String = 'http://maps.google.com/staticmap?center=' +
  57. lat + ',' + lng + '&format=jpg&zoom=15&size=' +
  58. mapWidth + 'x' + mapHeight + '&key=' + apiKey +
  59. "&markers="+lat+","+lng+","+"greena";
  60. // start map load
  61. loader.loadClip(mapUrl, _level0.info_mc.map_mc);
  62. _level0.info_mc.text_txt.text += "Loading, please wait...\n";
  63. }

Contacts Demo scr 4 Contacts Demo scr 5

Look more detailed informations in source codes:
- ContactsDemo_PTM.zip (include CS4 FLA, AS class files and PHP files)
- ContactsDemo_PTM.zip (includes only CS3 FLA):
- ContactsDemo.fla
- Contact.as
- Menu.as
- and a few PHP files to get Lat and Lng values from Google Maps.

Testing KuneriLite plugins part three: Take, play and send video file from Flash Lite to server

In my earlier Flash Lite article I've tested KuneriLite Camera plugin to take picture (klMode=picture). This time I've it's video support (klMode=video) to record video and store it to mobile phone. I've modified my ActionScript source code a little and it worked very nicely on the Nokia N95. This Flash Lite test application sends videos to my server http://ptm.fi/temp/videos folder, so check you uploaded videos from there.

PTM Video pic 1 PTM Video pic 2 PTM Video pic 3

Setting up system
This time I've tested KuneriLite wizard in Microsoft Vista. I've installed Active Perl and Symbian S60 3rd edition SDK Maintenance Release as I did earlier in my Camera and Upload plugins -article. I had to make small modifications to get KuneriLite Wizard working on vista. You can find these modifications on the KuneriLite Wiki: Microsoft Vista Support.

Flash Lite application
The idea of this application is take video, play it to user and send it to a remote server (if the user wants to send it). All the ActionScript code is written to first frame of timeline. I'll describe here only needed lines to understand how to take, show and send video file to the remote server. Please see the FLA source code for more information.

Initialize application
There is one major bug in my previous example with taking picture, have you noticed it? I haven't thought on the situation where a user start to take picture and then press back when Kuneri Lite Camera plugin is active. The application is trying to make a thumbnail picture, which fails if there is no picture taken. In this video example this situation is handled with Camera plugin Status operation (klStatus).

A few variables are defined to handle video filename and KuneriLite plugin gateway errors.

var vidName:String = "";          // video name
var klError:Number = -99;         // klError number
var klStatus:String = "";         // klStatus string
var process:Number = 0;           // process number
var intervalId:Number;            // interval number
var path:String = "\\Data\\Others\\Trusted\\PTMVideo\\";

Preparing Camera
KuneriLite offers optional prepare command which prepares the camera resource and checks the presence of camera device. I'll check this first and let then user take video.

// check camera condition
process = 1;
intervalId = setInterval(checkProcess,1000);
status_txt.text = "status: preparing camera...";
loadVariables("http://127.0.0.1:1001/Basic/camera?
               klCommand=prepare&klIndex=0","");

Taking video
This stage is very similar to the sending picture example from the previous article. The only visible modification is with Video instance. I’ve added one video symbol to the library and dragged it to the timeline (instance name is video). When a user presses the device’s number one key, KuneriLite uses loadVariables()-function to call Camera plugin in order to take video. Here I just take a full size video with main camera.

//Take video
function takeVideo(){
  // videoname
  vidName = giveDateAndTimeString();
  var command:String = "";
  command += "http://127.0.0.1:1001/Basic/camera?klCommand=start";
  command += "&klMode=video";
  command += "&klPath="+path+vidName+".3gp";
  command += "&klSize=full";
  command += "&klIndex=0";
  status_txt.text = "status: taking video...";
  process = 2;
  klError = -99;
  intervalId = setInterval(checkProcess,1000);
  loadVariables(command,"");
}

Did user take video or not
As I wrote earlier, I didn’t check if the user had taken a picture in my previous example. Here I will do it after the video screen is closed in KuneriLite plugin. I have one function which checks processes to see what had happened in my application. When Kuneri Lite Camera plugin is closed, I’ll start to check if there’s a video file taken or not.

// .. part of my prosess function
// check if video is taken
case 2:
  if (klError == -99) return;
  clearInterval(intervalId);
  if (klError == 0) {
    status_txt.text += "done!";
    intervalId = setInterval(checkVideo,2000);
  }
  process = 0;
  break;
//check is video taken
function checkVideo() {
  clearInterval(intervalId);
  var command:String = "http://127.0.0.1:1001/Basic/camera?klCommand=status";
  status_txt.text = "status: checking video...";
  process = 3;
  klError = -99;
  klStatus = "";
  intervalId = setInterval(checkProcess,1000);
  loadVariables(command,"");
}

If video is available, just start to play it.

// .. part of my prosess function
// is videofile available
case 3:
  if (klError == -99) return;
  clearInterval(intervalId);
  if (klError == 0) {
    status_txt.text += "done!";
    if (klStatus == "complete") {
      intervalId = setInterval(playVideo,2000);
    } else if (klStatus == "exit") {
      status_txt.text = "status: No video!";
    }
  } else {
    status_txt.text = "status: klError = "+klError;
  }
  process = 0;
  break;

Play video
After video is taken, it will be showed to user with video instance.

// Load and play video
function playVideo(){
  clearInterval(intervalId);
  status_txt.text = "status: playing video...";
  video.play(vidName+".3gp");
}

video.onStatus = function(info){
  if (info.code=="completed") status_txt.text += "done!";
}

Sending video file to remot server
Sending is handled the same way I used in my photo example. I added upload status checking to this example. First video will be sent to server and uploading is checked with own made checking function

function checkUploading() {
  clearInterval(intervalId);
  var command:String = "http://127.0.0.1:1001/Basic/uldl?klCommand=status";
  command += "&klTrId=1234";
  process = 5;
  klError = -99;
  klStatus = "";
  intervalId = setInterval(checkProcess,1000);
  loadVariables(command,"");
}

and process function is checking what is going on with uploading. KuneriLite sends a few different status, I used only two of them: complete if uploading is successfully completed or failed if there where some problems.

case 5:
  if (klError == -99) return;
    clearInterval(intervalId);
    if (klError == 0) {
      status_txt.text = "status:" +klStatus;
      if (klStatus == "complete" || klStatus == "failed") {
        process = 0;
      } else {
        intervalId = setInterval(checkUploading,1000);
      }
    } else {
      status_txt.text = "status(5): klError = "+klError;
      process = 0;
    }
  break;

Source and SIS files
This application is designed to run 240×320 screens and for testing purposes only. It uses KuneriLite’s default generated SIS package, so if you have my other examples installed you have to remove these first.

Sources: PTMVideo.zip (Flash Lite 2.0 Application)
SIS: PTMVideo_3rd_edition_signed.sis (install it to memory card!)

Feel free to try this example and send video greetings to me with Flash Lite!

Note! I have 20MB upload limit per file with PHP at my server, so dont take too long videos!

Testing KuneriLite plugins part two: Accelerometer plugin

I want to test N95 Accelerometer and I installed Nokia N95 Accelerometer plugin package and made a small test with KuneriLite Accelerometer plugin. After a few test I noticed that getting a new axis values takes around one second. Oh it is ok I think but finally I noticed that all redrawing of the UI is hang also for a second. I have installed a new firmware to my N95 with Flash Lite 3.0 Player, which seems to have XML Socket bug and very slow. You can read more from Forum Nokia thread and Kuneri bloggy.

Like you can see at below picture, calling XML Socket in KuneriLite Accelerometer plugin in Flash Lite 3.0 Player takes about 1 second, and it hang UI drawing also to same time.

True and sad :-(

Edit:
Getting a new axis values:
- Nokia N95 (V 21.0.0.16, Flash Lite 3.0 Player) about 1101 ms. (left)
- Nokia N95 (V 20.0.015, Flash Lite 2.0 Player) about 100 ms. (right)

PTM Accel Pic 1 PTM Accel Pic 2

Sources: PTMAccel.zip (Flash Lite 2.0 Application)
SIS: PTMAccel_3rd_edition_signed.sis (install it to phone memory)

Testing KuneriLite plugins part one: Camera and Upload plugins

Finally I got time to test KunerLite plugins. They have done 11 nice plugins to extend Flash Lite applications. Now I am going to test a few of them and write some lines here in my blog.

My first test is to do Flash Lite application which takes pictures and sends those to server side. This testing application sends pictures to my server http://ptm.fi/temp folder, so check you uploaded photos from there.

PTM Camera pic 1 PTM Camera pic 2 PTM Camera pic 3

Setting up system
I recently reinstalled Windows again, so I have to install Active Perl and Symbian S60 3rd edition SDK Maintenance Release back to my computer to get KuneriLite working. You can find all necessary information’s from KuneriLite Wizard Beginner's Guide (they have done excellent wiki for you which helps setting up KuneriLite to your computer). After Perl and S60 SDK is ready in your computer, you have to install KunerLite, you can download free Basic version from Kuneri’s web site.

Flash Lite application
The idea of application is to take picture and send it to server side. I decided to program Flash Lite 2.0 application because I don’t want to mess with old Flash Lite 1.1 code anymore :-) . All code is written to first frame of timeline, I will describe here only needed lines to understand taking and sending picture to server side. Please see source code for more information.

Initialize application
A few variables are defined to handle picture name and KuneriLite plugin gateway errors. I have made small delays between taking/storing picture, making thumbnail and loading thumbnail because you have to wait a little time to get picture ready to resize or loading. These processes are handled with process and intervalId variables and setIntervals. Pictures and thumbnails are stored in application installation directory.

var picName:String = "";
var klError:Number = -99;
var process:Number = 0;
var intervalId:Number;
var path:String = "\\Data\\Others\\Trusted\\PTMCamera\\";

Taking picture
When user press mobile phones number one key, a new mc is created to store and show picture’s thumbnail. KuneriLite uses loadVariables()-function to call Camera plugin to take picture. You can find more information about Camera plugin from their web site. Here I just take full size picture with main camera.

/* take picture */
function takePicture(){
  // create new mc to display new image
  if (image_mc != undefined) {
    removeMovieClip(image_mc);
    picture_txt.text = "";
  }
  this.createEmptyMovieClip("image_mc",this.getNextHighestDepth());
  image_mc._x = 40; image_mc._y = 105;
  picName = giveDateAndTimeString();
  var command:String = "";
  command += "http://127.0.0.1:1001/Basic/camera?klCommand=start";
  command += "&klMode=picture";
  command += "&klPath="+path+picName+".jpg";
  command += "&klSize=full";
  command += "&klIndex=0";
  status_txt.text = "status: taking picture...";
  bottom_mc.image_txt.text = "";
  process = 1; klError = -99;
  loadVariables(command,"");
}

Making thumbnail and show it to user
After picture is taken it will be resized and loaded to Flash Lite application. You can resize pictures with KuneriLite Camera plugin and load pictures with MovieClipLoader.

/* make thumbnail */
function resizePicture() {
  clearInterval(intervalId);
  var command:String = "";
  command += "http://127.0.0.1:1001/Basic/camera?klCommand=resize";
  command += "&klPath="+path+picName+".jpg";
  command += "&klSize=160*120";
  command += "&klTargetFile="+path+picName+"_thumb.jpg";
  status_txt.text = "status: resizing picture...";
  process = 2; klError = -99;
  loadVariables(command,"");
}

/* load picture */
var mcLoader:MovieClipLoader = new MovieClipLoader();
mcLoader.addListener(this);
function loadPicture(){
  clearInterval(intervalId);
  status_txt.text = "status: loading thumbnail...";
  mcLoader.loadClip(picName+"_thumb.jpg",image_mc);
  picture_txt.text = picName+".jpg";
}

function onLoadError(mc:MovieClip) {
  status_txt.text = "status: error loading thumbnail!";
}

function onLoadComplete(mc:MovieClip) {
  status_txt.text += "done!";
}

Sending original picture to server side
Sending is very similar process, just call KuneriLite Upload plugin and it sends picture to server. In server side you have to use for example PHP to get and store picture (you can find example PHP code from Kuneri’s web site). Remember give write permission to folder where images will be uploaded.

/* send picture */
function sendPicture(){
  var command:String = "";
  command += "http://127.0.0.1:1001/Basic/uldl?klCommand=upload";
  command += "&klTrId=1234";
  command += "&klUrl=http://www.ptm.fi/flashlite/kuneri/getImage.php";
  command += "&klFile="+path+picName+".jpg";
  command += "&klType=image/jpeg";
  status_txt.text = "status: sending picture...";
  process = 3; klError = -99;
  loadVariables(command,"");
}

There are also function which handles user interactivity with mobile keys and function which just check processes what is happening in Flash Lite application and updates dynamic status textfield. Please see those in source codes.

Creating SIS-file
You can create SIS file with KuneriLite Wizard. It is very easy process – create project, select plugins, add files to your project and finally create SIS file. I have made own cer and key files with makekeys command. More info to sign SIS files can be found for example from Adobes site.

Creating SIS file

Source and SIS files
This application is designed to run 240x320 screens and for testing purposes only. It uses KuneriLite’s default generated UID in SIS package.

Sources: PTMCamera.zip (Flash Lite 2.0 Application)
SIS: PTMCamera_3rd_edition_signed.sis (install it to phone memory)

It is amazing easy to do this kind of application with KuneriLite plugin’s, thanks to all KuneriLite team members!