Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 07-18-2012, 12:06 AM   #1
freezerguy
Registered User
 
Join Date: Sep 2004
Posts: 3
Question Shared Objects and a Datagrid

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
freezerguy is offline   Reply With Quote
Old 07-22-2012, 10:44 PM   #2
freezerguy
Registered User
 
Join Date: Sep 2004
Posts: 3
Default

Anyone have any ideas? I am at a total loss...I'm guessing I will need to loop, just not sure exactly how or the syntax.

Matt
freezerguy is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:25 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.