6
As you type into the search box, Google Suggest guesses what you're typing and offers suggestions in real time. This is similar to Google's "Did you mean?" feature that offers alternative spellings for your query after you search, except that it works in real time.
I had seen same feature done using Dot net, Ajax, and PHP etc.
You can also see the feature live here ObjectGraph Dictionary that’s suggests us as we type.
I utilized the event driven nature of Action Script 3.0 and I came with this SearchManager class or we can also say as flash version of Google suggest We have seen the Google suggest that will suggests the names according to the input values, I searched the web for suggest tool in flash, so I came up with this Manager class.
Type capital 'S' here..
Here the code in Flash
import com.flashflex.*;
//Array of data to be searchable
var toSearchArray:Array = new Array();
toSearchArray.push( "Belinda" );
toSearchArray.push( "Gina" );
toSearchArray.push( "Benny" );
toSearchArray.push( "Charlotte" );
toSearchArray.push( "Jane" );
toSearchArray.push( "Raja" );
toSearchArray.push( "Saravanan" );
toSearchArray.push( "Ramesh" );
toSearchArray.push( "Selva" );
toSearchArray.push( "Muza" );
toSearchArray.push( "Kalis" );
toSearchArray.push( "Prasath" );
toSearchArray.push( "Sharmila" );
toSearchArray.push( "Santha" );
toSearchArray.push( "Vijay" );
toSearchArray.push( "Bipin" );
toSearchArray.push( "Vinod" );
toSearchArray.push( "Vipin" );
toSearchArray.push( "Robert" );
toSearchArray.push( "Mahesh" );
toSearchArray.push( "Vel" );
toSearchArray.push( "Chitra" );
toSearchArray.push( "Ganesan" );
toSearchArray.push( "Mathan" );
toSearchArray.push( "Asan" );
toSearchArray.push( "sara" );
//Create objects of searchable items
var len:Number = toSearchArray.length;
for (var i:int = 0; i<len; i++) {
var _searchItem:SearchItem = new SearchItem(toSearchArray[i]);
addChild(_searchItem);
}
txtItem.restrict = "a-zA-Z";
txtInput.restrict = "a-zA-Z";
addSearchItem.addEventListener( MouseEvent.CLICK, handleAddSearchItem );
txtInput.addEventListener( Event.CHANGE, handleTextInputChange );
function handleAddSearchItem( event : MouseEvent ) {
var searchItemData : String = txtItem.text;
if ( searchItemData.length > 0 ) {
toSearchArray.push( txtItem.text );
var _searchItem:SearchItem = new SearchItem(txtItem.text);
addChild(_searchItem);
}
}
//Dispaching event to check the searchable data
function handleTextInputChange( event : Event ) {
SearchResult.clearData();
dispatchEvent(new ObjectEvent(ObjectEvent.OBJECT_EVENT, true, txtInput.text));
_resultList.dataProvider = (SearchResult.getResult());
}
Explanation for code:
Create an Array that holds the data to be searchable; here we have the data in toSearchArray.
Create objects to SearchItem and add to the display list since we extends MovieClip and also to get the Event bubbling to work.
for (var i:int = 0; i<len; i++) {
var _searchItem:SearchItem = new SearchItem(toSearchArray[i]);
addChild(_searchItem);
}
At the TextChange Event handler we are dispatching Object Event and adding the searchItem to list and displaying the whole list atlast.
function handleTextInputChange( event : Event ) {
SearchResult.clearData();
dispatchEvent(new ObjectEvent(ObjectEvent.OBJECT_EVENT, true, txtInput.text));
_resultList.dataProvider = (SearchResult.getResult());
}
Feel free to modify, extend and distribute the code..
Posted on 11:05 PM by Author and filed under
ActionScript 3.0
Google Suggest?As you type into the search box, Google Suggest guesses what you're typing and offers suggestions in real time. This is similar to Google's "Did you mean?" feature that offers alternative spellings for your query after you search, except that it works in real time.
I had seen same feature done using Dot net, Ajax, and PHP etc.
You can also see the feature live here ObjectGraph Dictionary that’s suggests us as we type.
I utilized the event driven nature of Action Script 3.0 and I came with this SearchManager class or we can also say as flash version of Google suggest We have seen the Google suggest that will suggests the names according to the input values, I searched the web for suggest tool in flash, so I came up with this Manager class.
Type capital 'S' here..
Here the code in Flash
import com.flashflex.*;
//Array of data to be searchable
var toSearchArray:Array = new Array();
toSearchArray.push( "Belinda" );
toSearchArray.push( "Gina" );
toSearchArray.push( "Benny" );
toSearchArray.push( "Charlotte" );
toSearchArray.push( "Jane" );
toSearchArray.push( "Raja" );
toSearchArray.push( "Saravanan" );
toSearchArray.push( "Ramesh" );
toSearchArray.push( "Selva" );
toSearchArray.push( "Muza" );
toSearchArray.push( "Kalis" );
toSearchArray.push( "Prasath" );
toSearchArray.push( "Sharmila" );
toSearchArray.push( "Santha" );
toSearchArray.push( "Vijay" );
toSearchArray.push( "Bipin" );
toSearchArray.push( "Vinod" );
toSearchArray.push( "Vipin" );
toSearchArray.push( "Robert" );
toSearchArray.push( "Mahesh" );
toSearchArray.push( "Vel" );
toSearchArray.push( "Chitra" );
toSearchArray.push( "Ganesan" );
toSearchArray.push( "Mathan" );
toSearchArray.push( "Asan" );
toSearchArray.push( "sara" );
//Create objects of searchable items
var len:Number = toSearchArray.length;
for (var i:int = 0; i<len; i++) {
var _searchItem:SearchItem = new SearchItem(toSearchArray[i]);
addChild(_searchItem);
}
txtItem.restrict = "a-zA-Z";
txtInput.restrict = "a-zA-Z";
addSearchItem.addEventListener( MouseEvent.CLICK, handleAddSearchItem );
txtInput.addEventListener( Event.CHANGE, handleTextInputChange );
function handleAddSearchItem( event : MouseEvent ) {
var searchItemData : String = txtItem.text;
if ( searchItemData.length > 0 ) {
toSearchArray.push( txtItem.text );
var _searchItem:SearchItem = new SearchItem(txtItem.text);
addChild(_searchItem);
}
}
//Dispaching event to check the searchable data
function handleTextInputChange( event : Event ) {
SearchResult.clearData();
dispatchEvent(new ObjectEvent(ObjectEvent.OBJECT_EVENT, true, txtInput.text));
_resultList.dataProvider = (SearchResult.getResult());
}
Explanation for code:
Create an Array that holds the data to be searchable; here we have the data in toSearchArray.
Create objects to SearchItem and add to the display list since we extends MovieClip and also to get the Event bubbling to work.
for (var i:int = 0; i<len; i++) {
var _searchItem:SearchItem = new SearchItem(toSearchArray[i]);
addChild(_searchItem);
}
At the TextChange Event handler we are dispatching Object Event and adding the searchItem to list and displaying the whole list atlast.
function handleTextInputChange( event : Event ) {
SearchResult.clearData();
dispatchEvent(new ObjectEvent(ObjectEvent.OBJECT_EVENT, true, txtInput.text));
_resultList.dataProvider = (SearchResult.getResult());
}
Feel free to modify, extend and distribute the code..
Cheers
Saravanan
its gr8 to see your reply.am a masters student in the field of remote engg.i jus have a small graphical interface both in HTML and flash.
I have sucessfully implemented this suggest tool for the box in HTML.Comin to flash i even dont know how to edit it and i dont have much more time to even learn flash.
Thats my problem basically and i would be glad if u can guide me through the process...
Thanks and regards
karteek vadde
What is the difficulty you are facing.. post it here ...
-sara
to begin the procedings, which IDE is more suitable for editing an existing '.fla' file and to append the given action script to it?
Hi Karteek,
That was done using .. you need flash cs3 software to edit the source file.
Check Adobe downloads page
--sara
Thanks.i will check it out and come up wid some more doubts.thanx for the rply.
Interesting demo. I created something similar with Silverlight (link below), but I am really tempted to try it in Flash now.
http://innodeskpoc.blogspot.com/2009/02/my-first-silverlight-app-demo.html
Thanks,
Tg
Post a Comment