Hello Everyone,
I am need of some serious help. I have searched without luck, sometimes 10 pages deep into Google, on how to save an editable datagrid into a shared object so that the next time I open the swf it retrieves the sharedobjects and populates the datagrid. Here is what I have for code:
Code:
import flash.net.SharedObject;
import fl.data.DataProvider;
import flash.events.MouseEvent;
stage.focus = myreminder;
btnAnother.addEventListener(MouseEvent.CLICK, another);
btnRemove.addEventListener(MouseEvent.CLICK, remove);
clrbtn.addEventListener(MouseEvent.CLICK, clr);
savebtn.addEventListener(MouseEvent.CLICK, saveit);
dg.editable = false;
dg.sortableColumns = true;
dg.width = 380
dg.rowCount = 3;
dg.columns = ["Reminder", "DueDate"];
//Shared Objects------------------------------------------------------------------------------------
var savedinfo:SharedObject = SharedObject.getLocal("reminderdata");
if (savedinfo.data.reminderdata != undefined){
//Trace information only
trace("There is info");
for (var variableNames in savedinfo.data) {
trace("Variable name="+variableNames +
" value="+savedinfo.data[variableNames]);
}
//End trace information
//var i:int;
//for each(var prop in savedinfo.data){
dg.addItem(savedinfo.data.reminderdata);
//}
} else {
var sampleItem0:Object = { Reminder:"New Reminder", DueDate:"New DueDate" };
dg.addItem(sampleItem0);
}
//End of Shared Objects------------------------------------------------------------------------------
function another(mevt:MouseEvent):void {
var i:int;
var arrNew:Array = new Array(myreminder.text,mydate.text);
var newObject:Object;
newObject = { Reminder:String(arrNew[0]), DueDate:String(arrNew[1]) };
dg.addItem(newObject);
dg.scrollToIndex(dg.length-1);
stage.focus = myreminder;
myreminder.setSelection(0,13);
//savedinfo.data.reminderdata = { Reminder:String (arrNew[i]), DueDate:String (arrNew[i])};
savedinfo.data.reminderdata = (newObject);
savedinfo.flush();
trace(savedinfo);
}
function remove(mevt:MouseEvent):void {
var i:int;
if (dg.length == 0) {
return;
}
for (i=0; i<dg.length; i++) {
if (dg.isItemSelected(dg.getItemAt(i))) {
dg.removeItemAt(i);
dg.scrollToIndex(i);
dg.clearSelection();
break;
}
}
}
function isGood(arr:Array):Boolean {
if ((arr[0] == "") || (arr[1] == "")){
return false;
}
return true;
}
function clr (mevt:MouseEvent):void{
savedinfo.clear();
}
function saveit(mevt:MouseEvent):void {
savedinfo.flush();
}
trace ("sample item is "+sampleItem0);
I can add items to the datagrid with no problem. When I close the swf and reopen it, the datagrid is only recalling the single last entry that I made. How do I get it to save the entire datagrid to a sharedobject and not just the last entry? I am really lost on this one. Any help is greatly appreciated.
Matt