You Are Here:

Community: Wiki

This page was last modified 01:31, 31 October 2008.

How to create a chat by Bluetooth using Kuneri Lite

From Forum Nokia Wiki

Contents

Introduction

In this tutorial we will follow a step-by-step guide to create a chat by Bluetooth using Kuneri Lite. Kuneri Lite allows access to the S60 features (Bluetooth, GPS, Camera, …) that we haven’t access directly from Flash Lite. More details about Kuneri Lite.


Creating KuneriLoader class

First of all, you’ve to create a separate ActionScript file called KuneriLoader.as. This file will be responsible by all received and sent messages. Put the following code in it.


/*
author: Flash Lite Effort - Embedded Systems and Pervasive Computing Lab.
version: 0.1
modified: 10/07/2008
*/
 
class KuneriLoader {
 
	private var loader:LoadVars;
 
	public function  KuneriLoader(){
		this.loader = new LoadVars();
	}
			
	public function KLoad(url:String, handler){
		loader.onLoad = function()
		{
			handler(this);
		}
		
		trace("LOADING: " + url);
 
		loader.load(url);
	}
	
	public function KError(msgError:String, klError:String){
		trace("KuneriLite: " + klError + " " + msgError);
	}
}

The KLoad function receives an url and a callback function as parameter, the callback function will be called after the resquest to the Kuneri Lite is done. (Remember that trace function result is not visible in device).


Creating the chat

After this, create a Flash Lite file (.fla). In the first frame put a button that will to open a connection to Kuneri Lite, with ‘connect_btn’ as instance name. Also put a dynamic text with ‘info’ as instance name.


Image:Connect.PNG


Create a layer (named ‘labels’) to put all labels and set the first frame name as ‘connect’. Create another layer (named ‘actions’) to put all actions. In the first frame of the ‘actions’ layer, paste the bellow code:

//Import the class KuneriLoader.
import KuneriLoader;
//Create a instance the KuneriLoader.
var loader = new KuneriLoader();
 
var kuneriPath:String = "http://127.0.0.1:1001/Basic/";
_quality = "HIGH";
fscommand2("FullScreen", true);
 
//Initially the bluetooth is started and response is returned to kuneriStarted.
loader.KLoad(kuneriPath + "connect?klCommand=start&", kuneriStarted);	
 
//After the button click connect this function will call.
connect_btn.onRelease = function():Void {
	//Connect the other device and the response will returned to kuneriConnected.
	loader.KLoad(kuneriPath + "connect?klCommand=connect&", kuneriConnected);	
	info.text = "Waiting...";
}
 
function kuneriConnected(res:LoadVars){
	if (res.klError != 0)
		info.text = "Erro in connection.";
}
 
function kuneriStarted(res:LoadVars){
	if (res.klError != 0){
		info.text = "Erro while starting.";
		//Send again. 
		loader.KLoad(kuneriPath + "connect?klCommand=start&", kuneriStarted);
	}
	else info.text = "Bluetooth started.";
}
 
function kuneriStatus(res:LoadVars){
	if (res.klError != 0){
		info.text = "Erro status.";
	}
	//Verify this status is connected with other device.
	else if (res.klStatus eq "connected"){
			//Stop the update status.
			clearInterval(sts);
			gotoAndPlay("chat");
	}
}
 
function getStatus():Void{
	//Get status the kuneri Lite and response.
	loader.KLoad(kuneriPath + "connect?klCommand=status&", kuneriStatus);	
}
 
//Each 700 milliseconds this status is updated.
sts = setInterval(getStatus, 700);
stop();

Yet in the ‘actions’ layer type the following code:

send_btn.onRelease = function():Void {
	if (msgText.text != ""){
		//Sends your message to other user.
		loader.KLoad(kuneriPath + "connect?klCommand=send&klMessage=" + msgText.text + "&", kuneriSend);
		info.text = "Sending...";
	}
}
 
function kuneriSend(res:LoadVars){
	if (res.klError != 0)
		info.text = "Erro sending the message.";
	//After send the message, textChat will updated.
	else uptadeSendChat();
}
 
function uptadeSendChat():Void {
	info.text = "";
	//Update chatText.
	chatText.text += ">> " + msgText.text + "\n";
	chatText.scroll = chatText.maxscroll;
	//Clear the msgText.
	msgText.text = "";
}
 
update_btn.onRelease = function():Void {
	//Read the message sends from other user.
	loader.KLoad(kuneriPath + "connect?klCommand=read&", kuneriRead);
	info.text = "Reading...";
}
 
function kuneriRead(res:LoadVars){
	if (res.klError != 0)
		info.text = "Erro reading.";
	//After read the message, textChat will updated.
	else uptadeReadChat(res.klReceive);
}
 
function uptadeReadChat(msg:String):Void {
	info.text = "";
	//Update the chatText.
	chatText.text += ">> " + msg + "\n";
	chatText.scroll = chatText.maxscroll;
}
stop();

In the stage put other buttons with ‘update_btn’ and ’send_btn’ instance names, a TextInput component with ‘msgText’ instance name and two ‘Dynamic Text’ with ‘chatText’ and ‘info’ instance names respectively. Like showed in the Figure.


Image:Chat.PNG


If you want to test your application, you must make a .sis file in the Kuneri Lite and install in the mobile phone. To get more informations about the creation of .sis files, click [1].

More

See more applications in Flash Lite Effort

Download

Download source files.

Author

--Felipe Sampaio 15 July 2008

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditFurlTechnocratiMagnoliaTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fHowE5ftoE5fcreateE5faE5fchatE5fbyE5fBluetoothE5fusingE5fKuneriE5fE4citeX qdcZpublisherQUxhttpE3aE2fE2fswE2enokiaE2ecomE2fidE2fc764fd1cE2d8b06E2d499aE2d9a6aE2d17c3903d5a65E2fforumE5fnokiaE5fcrawlerE5fagentX qdcZtitleQSxHowE20toE20createE20aE20chatE20byE20BluetoothE20usingE20KuneriE20E4citeE20E2dE20ForumE20NokiaE20WikiX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfnTypeZCommunityContentQ qdcZtypeQUqfnTypeZE52esourceQ qdcZtypeQUqfnTypeZWebpageQ qdcZtypeQUqfnTypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qrssZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qfnZdistributionQUxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2fX qfnZtopicQUqfnTopicZbluetoothQRqdcZtypeQUqrdfsZE52esourceQRqmarsZrelevanceQNx100X qfnZtopicQUqfnTopicZconnectivityQRqmarsZrelevanceQNx100X qfnZtopicQUqfnTopicZflashQRqmarsZrelevanceQNx100X qfnZtopicQUqfnTopicZflashE5fliteQRqdcZtypeQUqrdfsZE52esourceQRqmarsZrelevanceQNx100X qfnZtypeQUqfnTypeZCommunityContentQ qfnZtypeQUqfnTypeZE52esourceQ qfnZtypeQUqfnTypeZWebpageQ qfnZtypeQUqfnTypeZWikiContentQ qfnZupdatedQDx2008E2d10E2d02X qfnZuserE5ftagQSxbluetoothX qfnZuserE5ftagQSxbluetoothX qfnZuserE5ftagQSxconnectivityX qfnZuserE5ftagQSxflashX qfnZuserE5ftagQSxflashX qfnZuserE5ftagQSxflashE2dliteX qfnZuserE5ftagQSxkuneriX qfnZuserE5ftagQSxkuneriliteX qfnZuserE5ftagQSxliteX qfnZuserE5ftagQSxs60X qmarsZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfnTypeZCommunityContentQ qrdfZtypeQUqfnTypeZE52esourceQ qrdfZtypeQUqfnTypeZWebpageQ qrdfZtypeQUqfnTypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ