Flash CS3 - Flash AutoComplete And Cookie
Try it here
Download AutoComplete.zip
package {
import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.text.*;
import fl.data.DataProvider;public class cookies extends Sprite {
var soDomain:String="FlashAutoCompleteCookieTest";
//Returns a reference to a locally persistent shared object that is only available to the current client. If the shared object does not already exist, this method creates one. If any values passed to getLocal() are invalid or if the call fails, Flash Player throws an exception.
var so:SharedObject=SharedObject.getLocal(soDomain);var ObjectCount=new int;
var CookieArray:Array = new Array();
public function cookies():void {
saveBtn.addEventListener(MouseEvent.CLICK,saveHandler);
deleteBtn.addEventListener(MouseEvent.CLICK,deleteHandler);if (so.data['ObjectTotal'] == undefined) {
so.data['ObjectTotal']=0;
so.flush();
}
ObjectCount=so.data['ObjectTotal'];readObject();
UpdateData();
}function addDataToObject(DataName:String,DataValue:String):void {
so.data[DataName]=DataValue;
so.flush();
CookieArray.push(DataValue);
//trace("Value added: " + so.data[DataName]);
UpdateData();}
function deleteObject():void {
so.clear();
//trace("Shared Object deleted");
so.data['ObjectTotal']=0;
CookieArray.splice(0 ,CookieArray.length);
CookieList.removeAll();
autoComplete.text="";
autoComplete.dataProvider = new DataProvider(CookieArray);
}
function readObject():void {
for (var i:int=0; i < ObjectCount; i++) {
//trace("Shared Object Value : " + so.data[i]);
CookieArray.push(so.data[i]);
}
}//Handlers
function saveHandler(e:MouseEvent):void {
if ((CookieArray.indexOf(autoComplete.text))==-1&&autoComplete.text!="") {
addDataToObject(String(ObjectCount),autoComplete.text);
so.data['ObjectTotal']=++ObjectCount;
so.flush();
} else {//trace("exist");
}
}
function deleteHandler(e:MouseEvent):void {
deleteObject();
}
function UpdateData() {
CookieList.dataProvider = new DataProvider(CookieArray);
autoComplete.dataProvider = new DataProvider(CookieArray);
}
}//
}//
Comments
Work from home India