×
Namespaces

Variants
Actions

Archived:Modifying contacts in Flash Lite

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

We do not recommend Flash Lite development on current Nokia devices, and all Flash Lite articles on this wiki have been archived. Flash Lite has been removed from all Nokia Asha and recent Series 40 devices and has limited support on Symbian. Specific information for Nokia Belle is available in Flash Lite on Nokia Browser for Symbian. Specific information for OLD Series 40 and Symbian devices is available in the Flash Lite Developers Library.

This code snippet demonstrates how to browse and modify contacts in the default phonebook using the Contact Platform Service for Flash Lite supported from S60 5th Edition onwards.

Article Metadata
Code ExampleTested with
Devices(s): Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 5th Edition and later
Symbian
S60 5th Edition
Article
Keywords: Service.Contact, contact.GetList(), contact.Add()
Created: User:Nokia Developer KB (26 Jan 2009)
Last edited: hamishwillee (14 May 2013)

Contents

Preconditions

Note.pngNote: Updating a contact with this application will erase all other contact information that is not shown in the form.

Source

// Import Platform Service Interface
import com.nokia.lib.Service;
/**********************************************************
** Set Device properties with fscommand2
**********************************************************/

// Enable Full Screen
fscommand2( "FullScreen", true );
// Set quality
fscommand2( "SetQuality", "high" );
 
/**********************************************************
** Define all variables and arrays
**********************************************************/

var outList;
var inParams;
var outParams
var outputEntry;
var errorId;
 
var firstName;
var lastName;
var mobile;
var email;
 
var contactId;
var contactEntry;
var contact;
 
var i = 0;
 
var idList:Array = new Array();
var firstnameList:Array = new Array();
var lastnameList:Array = new Array();
var mobileList:Array = new Array();
var emailList:Array = new Array();
 
// Heading of the application
heading_txt.text = "Modify Contacts";
// Get list of the contacts
listContacts();
// Define number of the last item
var lastItem = idList.length-1;
// Trace information of the contact to the form
setTexts();
 
/**********************************************************
** Function for setting the texts to inputs
**********************************************************/

function setTexts() {
nro_txt.text = i+1+"/"+idList.length;
 
if(firstnameList[i] == undefined) {
firstname_txt.text = "";
} else {
firstname_txt.text = firstnameList[i];
}
 
if(lastnameList[i] == undefined) {
lastname_txt.text = "";
} else {
lastname_txt.text = lastnameList[i];
}
 
if(mobileList[i] == undefined) {
mobile_txt.text = "";
} else {
mobile_txt.text = mobileList[i];
}
 
if(emailList[i] == undefined) {
email_txt.text = "";
} else {
email_txt.text = emailList[i];
}
 
}
 
/**********************************************************
** Function for getting updated list of the contacts
**********************************************************/

function listContacts() {
// Create new Service object which has Contact data
contact = new Service("Service.Contact", "IDataSource");
 
// Define input parameters for the contact list
inParams = {Type:"Contact"};
 
// Define result value
outParams = contact.GetList(inParams);
if (outParams.ErrorCode == 0) {
outList = outParams.ReturnValue;
outputEntry = null;
// Format arrays
idList = [];
firstnameList = [];
lastnameList = [];
mobileList = [];
emailList = [];
do {
outputEntry = outList.next();
if (null != outputEntry) {
// Get the lists of IDs and firstname to Arrays
idList.push(outputEntry.id);
firstnameList.push(outputEntry.FirstName["Value"]);
lastnameList.push(outputEntry.LastName["Value"]);
mobileList.push(outputEntry.MobilePhoneHome["Value"]);
emailList.push(outputEntry.EmailHome["Value"]);
} else {
break;
}
} while (true);
} else {
// if errors trace them to the textfield
errorId = outParams.ErrorCode;
error_txt.text = "Error while listing: "+errorId+"\r";
}
}
 
/**********************************************************
** Function for pressing the Prev button
**********************************************************/

prev_mc.onPress = function() {
if(i == 0) {
i = lastItem;
} else {
i--;
}
setTexts();
error_txt.text = "";
}
 
/**********************************************************
** Function for pressing the Next button
**********************************************************/

next_mc.onPress = function() {
if(i == lastItem) {
i = 0;
} else {
i++;
}
setTexts();
error_txt.text = "";
}
 
/**********************************************************
** Fuction for updating the contact information when Save
** button is pressed.
** NOTE! Updating contact with this application will erase
** all other information of the contact which are not
** shown in this form
**********************************************************/

save_mc.onPress = function() {
firstName = {Label:"First Name", Value:firstname_txt.text};
lastName = {Label:"First Name", Value:lastname_txt.text};
mobile = {Label:"Mobile", Value:mobile_txt.text};
email = {Label:"E-mail", Value:email_txt.text};
contactId = idList[i];
contactEntry = {
id:contactId, FirstName:firstName, LastName:lastName,
MobilePhoneHome:mobile, EmailHome:email
};
 
// Define input parameters
inParams = {Type:"Contact", Data:contactEntry};
 
// Define result data
outParams = contact.Add(inParams);
if (outParams.ErrorCode == 0) {
error_txt.text = "Contact updated";
} else {
errorId = outParams.ErrorCode;
error_txt.text = "Error: "+errorId;
}
listContacts();
}
 
/**********************************************************
** Function for pressing the Exit button.
**********************************************************/

exit_mc.onPress = function() {
status = fscommand2("Quit");
trace("QUIT");
}
 
// Stop the timeline
stop();

Postconditions

You can browse all the contacts and edit them by modifying the fields and pressing Save.

Example application

The following sample application has been tested in the Nokia 5800 XpressMusic (S60 5th Edition, Flash Lite 3.0): File:FlashLite Modifying Contacts.zip

See also

This page was last modified on 14 May 2013, at 02:59.
46 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×