Home » Flash Lite, Programming

Testing Kuneri Lite plugins: Camera and Upload

By Pasi Manninen 19 August 2008 One Comment

Pasi Manninen decided to test KunerLite plugins and report to the community. Kuneri have done 11 nice plugins to extend Flash Lite applications and Pasi went out to test some of them.

My first test was to do Flash Lite application which takes pictures and sends them to a remote server. This example application sends pictures to http://ptm.fi/temp which is a folder on my server. If you use the same settings check your uploaded photos on that address, too.

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

> Setting Up The System

I recently reinstalled Windows again, so I had to install Active Perl and Symbian S60 3rd edition SDK Maintenance Release back in order to get KuneriLite working. You can find all the necessary information on KuneriLite Wizard Beginner’s Guide (they have done an excellent wiki which helps setting up KuneriLite on your computer). After Perl and S60 SDK are fully installed, you have to install KunerLite. You can download a free Basic version from Kuneri’s website.

> Example Flash Lite Application

The idea of the application is to take a picture and send it to the remote server. I’ve decided to code a Flash Lite 2.0 application because I didn’t want to mess around with old Flash Lite 1.1 code anymore :-). All the code is written to the first frame of the timeline. I’ll describe here only the needed lines to understand how to take a picture and send it to the server. Please see source code for the rest of the code.

> Initialize The Application

There are a few variables handling the picture name and KuneriLite plugin gateway errors. I’ve made a small delay in several places, like between taking/storing picture, making thumbnail and loading thumbnail, because you have to wait a little while before the picture is ready to resize or loading. These are handled with a process and intervalId variables, and setIntervals. Pictures and thumbnails are stored in the 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 a picture

When a user presses the number one key on the phone, a new mc is created to store and show picture’s thumbnail. KuneriLite uses loadVariables() function to call the Camera plugin to take a picture. You can find more information about the Camera plugin on their website. In this example I just take a full size picture with the 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 A Thumbnail And Showing It

After a picture is taken, it’s being resized and loaded to the 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

Sending is a very similar process, just call KuneriLite Upload plugin and it sends the picture to the server. On the server side you have to use a script (for example, in PHP) in order to get and store the picture (you can use the example PHP code from Kuneri’s web site). Remember to give write permission (chmod) 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 functions which handle user interactivity with the keys and a function which just check what is happening in the Flash Lite application process and updates the dynamic status textfield. Check these out in the source code below.

> Creating a SIS-file

You can create SIS file with KuneriLite Wizard. It’s a very easy process: Create a project, select plugins, add files to your project and finally create SIS file. I’ve made my 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 Code and SIS files

This application is designed to run on 240×320 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 amazingly easy to do this kind of application with KuneriLite plugins, thanks to all the KuneriLite team members!

[This article was first posted on Pasi's Blog.]

One Comment »

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.