Sunday, May 1, 2011

Creating an application in flash for searchin phonebook

Hi, in this tutorial you will learn how to build a flash application to search the phonebook. Also you will come to know how to handle input field and many more aspect of flash scripting.

1. Create a new file in flash. choose the background color and dimension. for make this application more appropriate choose a telephone image from anywhere you like and import it to flash stage with Ctrl+R.

2. With the help of text tool make an input text area. give it a instance name like "nameField".

3. you can also set a background for that input text by making a solid colored rectangle shape below text field.

4. now create an rectangle below type over it like search. select rectangle and search text and convert it to button. give it an instance name "searchButton".

5. Now below search button make an input text and give it an instance name "resultField" also you can give it a background as you gave to nameField.

6. Now action scripting part:

Make a new layer name it actionscript and on the first frame paste below given script

var directory:Array = [{name:"Sven", phone:"854-664-9652"}, {name:"Michel", phone:"459-6996-4522"}, {name:"Jack", phone:"895-659-4485"}, {name:"Charly", phone:"956-8596-5243"}, {name:"Ana", phone:"127-25485-6695"}];

function getPhoneByName(name:String):String {
for(var i:Number = 0; i < directory.length; i++) {
if(directory[i].name.toLowerCase() == name.toLowerCase()) {
return directory[i].phone;
}
}
return "No Match";
}

searchButton.onRelease = function() {
resultField.text = getPhoneByName(nameField.text);
}

Script explanation:

This script:

var directory:Array = [{name:"Sven", phone:"854-664-9652"}, {name:"Michel", phone:"459-6996-4522"}, {name:"Jack", phone:"895-659-4485"}, {name:"Charly",

phone:"956-8596-5243"}, {name:"Ana", phone:"127-25485-6695"}];

create a directory with five objects, and every object has properties, name and phone.

This script

function getPhoneByName(name:String):String {
for(var i:Number = 0; i < directory.length; i++) {
if(directory[i].name.toLowerCase() == name.toLowerCase()) {
return directory[i].phone;
}
}
return "No Match";
}

defines a function that will be searching directory field to find the concerned phone number. This function like parameter, accept the name and returns result as string.

And this script:

searchButton.onRelease = function() {
resultField.text = getPhoneByName(nameField.text);
}

provides us, that on click on the search button we have a final result.

We're done!

Test your Movie (Ctrl+Enter).


Source: https://sites.google.com/site/pageflipsite/circle/1842621_PhoneBook.fla?attredirects=0&d=1

No comments:

Post a Comment