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.
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