Advanced coder advice needed - Shared Object

Hi,
This is my first time to this forum, be gentle. I need some help organizing a project that uses different shared objects. I suspect I might be going about this all wrong.

The project is a campground booking manager. I started this to be based off of a calander app I made that uses the shared object to save data. The calander works fine by itself. I added a file manager SO that was donated by Gaius Coffey. It works for saving,creating, or deleting SO’s for each campsite user. The problem I cant seem to figure out, is how to wrap both of those in a shared object for each individual campsite. I have tried arranging this in a couple of different ways,… using the calander SO as the overall so, but I cant get it to populate with each campsite, … same thing with using the file manager as the overall SO. I have several date and time variables in my code that I have tried to associate with all the SO’s, but I can’t seem to work this out. I know this may seem complicated, but maybe that is part of my prob. Is there an easier way to organize this? Here is a demo of what I have now… if anyone is interested in looking at this, I will post the fla…

[color=#606420]http://ntdesigns.net/downloads/newCampDemo.swf[/color]

edit*** To operate, select a day on the calander to save text to or set the reserved feature by day. You can only read messages if the read option is selected, same with set reserve.Select a campsite to bring the campform into view. The file manager is in the campform.

Thanks in advance
NTD

I would suggest you create a function that will loop through the data normally stored to the two SOs and join them into a single array. Save this array to the SO and it should be easy to retrieve with a function the reverse of the above mentioned one to separate the data upon loading.

Hi,
Thanks for the reply. I have tried this for some time now and I can’t seem to get it. The calander part of the form saves the data in two arrays and I have tried to manage everything from there…


for (n=0; n<37; n++) {
 myArray[n+37*themonth] = _root.campForm["txtMsg"+n];
 resArray[n+37*themonth] = _root.campForm["dayselect"+n]._alpha;
}

These arrays are affected by the calander, I cant figure out how to add an overall shared object here for everything. This seems to be the way to go as it would allow the management of the info by date. The file manager is seperate and holds camper info, but it is not my code and I dont understand it very well so I have not been able to modify it to be the overall Shared Object. My next try was to create an overall shared object that could hold the data of both the camper info and the calander in an individual campsite shared object. This is pretty much where I am stuck now. It just seems like too much information to manage,… at least for me. I am open to any suggestions at this point… I am possibly making things more difficult with my description. If you would like a look at the fla…

http://ntdesigns.net/downloads/newCampDemo.fla

Thanks again
NTD

Sorry, I don’t use Flash so I can’t view your fla (I use Ming).

I’m not sure why you are trying to combine the two SOs. They can be left alone so long as they have different names, and loaded separately.

If you really need to combine them, find the lines in your code where they are set and create an array of arrays from this data to store in a single SO.

Bummer,
I wish you had flash. I have read some of your posts and you would probably understand what I am trying to do and be able to tell me how to do it correctly. I understand the basics of using the shared object and the basics of using arrays. However, once I get a few of both going in this movie, I seem to get lost on how to manage them. The problem with the shared objects as they are is that they will only save data independently. The calander will save text and an alpha reserved feature for any day, month, or year. This is achieved with the use of two arrays in the shared object for the calander. The file manager is independent and only saves camper info data. It will not change. It should be dependent on which campsite is selected. The calander should also be dependent on which campsite is selected. The calander MC is 5 frames long and the code looks like this…

frame 1


now = new Date();
readArray = new Array();
alphaArray = new Array();
myArray = new Array();
resArray = new Array();
dayOfWeek = now.getDay();
theMonth = now.getMonth();
todaysDate = now.getDate();
thisYear = now.getFullYear();
txtnow = now.toString().slice(0, 10)+now.toString().slice(28);
function displayMonth(thisYear, thisMonth) {
start = new Date(thisYear, thisMonth, 1, 2);
startDay = start.getDay();
_root.main["msg"+(todaysDate+startDay)].backgroundColor = "0x66FFFF";
for (n=27; n<33; n++) {
enddate = new Date(thisYear, thisMonth, n);
if (enddate.getDate() == 1) {
lastDate = n-1;
break;
}
}
v = 1;
for (t=startDay; t<(lastDate+startDay); t++) {
_root.main["txt"+t] = v;
v++;
}
}
function convertMonth(thisMonth) {
if (thisMonth == 0) {
month = "January";
} else if (thisMonth == 1) {
month = "February";
} else if (thisMonth == 2) {
month = "March";
} else if (thisMonth == 3) {
month = "April";
} else if (thisMonth == 4) {
month = "May";
} else if (thisMonth == 5) {
month = "June";
} else if (thisMonth == 6) {
month = "July";
} else if (thisMonth == 7) {
month = "August";
} else if (thisMonth == 8) {
month = "September";
} else if (thisMonth == 9) {
month = "October";
} else if (thisMonth == 10) {
month = "November";
} else if (thisMonth == 11) {
month = "December";
}
return month;
}
displayMonth(thisYear, theMonth);
txtMonth = convertMonth(theMonth);
txtMonth = txtMonth+"				 " +thisYear;

Frame 2


for (n=0; n<37; n++) {
myArray[n+37*themonth] = _root.main["txtMsg"+n];
calResArray[n+37*themonth] = _root.main["dayselect"+n]._alpha;
}
for (i=1;i<98;i++){
resArray[i+98*themonth] = _root.main["reserve"+n]._alpha;
 
}
function getFile(filename,whichyear) {
filename = "Calendar"+filenumber+"_"+whichyear;
myCalSO = SharedObject.getLocal(filename, "/");
if (myCalSO.data.detailsr == null) {
myCalSO.data.detailsr = myArray;
myCalSO.data.detailsa = calResArray;
myCalSO.data.detailsR = resArray;
myCalSO.flush();
}
readArray = myCalSO.data.detailsr;
alphaArray = myCalSO.data.detailsa;
reserveArray = myCalSO.data.detailsR;
}
getfile(filename,thisYear);

frame 3


for (n=0; n<37; n++) {
_root.main["txtMsg"+n] = readArray[n+37*theMonth];
_root.main["dayselect"+n]._alpha = alphaArray[n+37*theMonth];
}
for (i=1; i<98; i++) {
_root.main["reserve"+i]._alpha = reserveArray[i+98*theMonth];
}

frame 4


for (n=0; n<37; n++) {
readArray[n+37*theMonth] = _root.main["txtMsg"+n];
alphaArray[n+37*theMonth] = _root.main["dayselect"+n]._alpha;
}
for (i=1; i<98; i++) {
reserveArray[i+98*theMonth] = _root.main["reserve"+i]._alpha;
}
myCalSO.data.detailsr = readArray;
myCalSO.data.detailsa = alphaArray;
myCalSO.data.detailsR = reserveArray;
 

frame 5


gotoAndPlay(4);

I have tried adding a campsite array to this but I cant seem to get it to save the data for each site,… it is always indendent. It seems like this is where I need to be adapting my code instead of creating more shared objects. The file manager shared object was donated by Gaiuss Coffey. After exploring it some I thought that maybe this would be a better way of “wrapping” the whole thing in a shared object manager, but this does not work correctly as I can’t figure out how to add to the code for individual campsites.

Camper File manager from Gaiuss Coffey…


function SO_Manager(_soname, _sosize, _sopath) {
this._sopath = _sopath;
if (_soname == undefined) {
trace("SO_Manager: NO SHARED OBJECT SPECIFIED.");
return;
}
this._soname = _soname;
this._SO = SharedObject.getLocal(this._soname, this._sopath);
if (this._SO.data.files == undefined) {
this._SO.data.files = new Object();
}
this._files = this._SO.data.files;
this._currentfile = undefined;
this._SO.flush(_sosize);
}
SO_Manager.prototype.flush = function() {
this._SO.flush();
};
SO_Manager.prototype.setFile = function(so_file) {
if (so_file == undefined) {
trace("SO_Manager: NO FILE SPECIFIED FOR SETFILE OPERATION.");
return;
}
if (this._files[so_file] == undefined) {
this._files[so_file] = new Object();
}
this._currentfile = so_file;
return this._files[this._currentfile];
};
SO_Manager.prototype.setFieldsAndFileFromMC = function(MC, so_file) {
if (MC == undefined) {
trace("SO_Manager: NO MOVIE SPECIFIED. WIPE LIST AND EXIT.");
this.fieldList = undefined;
return;
}
if (so_file == undefined) {
so_file = MC._name;
}
this.setFile(so_file);
this.fieldList = new Array();
for (var i in MC) {
if (typeof (MC*) == "object" && MC*.text != undefined && MC*.type == "input") {
this.fieldList.push(i);
}
}
};
SO_Manager.prototype.storeFileFromMC = function(MC, so_file) {
this.setFieldsAndFileFromMC(MC, so_file);
var f = this.setFile(so_file);
for (var i in this.fieldList) {
f[this.fieldList*] = MC[this.fieldList*].text;
}
this._SO.flush();
};
SO_Manager.prototype.deleteThisFile = function(so_file) {
var file = so_file == undefined ? this._currentFile : so_file;
var f = this._files[file];
this._currentfile = undefined;
for (var i in f) {
delete f*;
}
this._SO.flush();
trace("SO_Manager: DEL "+file);
delete this._files[file];
this._SO.flush();
};
SO_Manager.prototype.retrieveFileToMC = function(MC, so_file) {
if (MC == undefined) {
trace("SO_Manager: NO MC SPECIFIED FOR RETRIEVE FILE OPERATION.");
return;
}
if (so_file == undefined) {
so_file = MC._name;
}
var f = this.setFile(so_file);
for (var i in f) {
MC*.text = f*;
}
return so_file;
};
SO_Manager.prototype.listAvailableFiles = function() {
var a = new Array();
for (var i in this._files) {
a.push(i);
}
return a.sort();
};

Now, I also created an array for the campsites, but I dont know how to tie it into the other shared objects. They all work, just independently of each other. I should be able to select a date on the calander and have the visually reserved freature show which sites are taken and populate the calander and the camper info for that day depending on which campsite is selected. The code for creating a SO for each campsite looks like this… The campsite function is empty because I cant figure out how to add the file manager or calander SO’s there.


function CampSite() {
}
CampSite.campArray=new Array();
CampSite.reserveCampSite=function(ithCamp) {
		if (campSO.data.campsites[ithCamp] == undefined) {
				campSO.data.campsites[ithCamp] = new Object();
		}
		var result=campSO.flush();
		result==true? trace("saved!"+ ithCamp) : trace("failed...");
		return result;
}
CampSite.deleteCampsite=function(camp) {
		for (var i in campSO.data.campsites[camp]) {
				delete campSO.data.campsites[camp]*;
		}
		delete campSO.data.campsites[camp];
		campSO.flush();
}
 
CampSite.doRelease=function(i) {
		_root.main["camp"+i].onRelease = function() {
				CampSite.campArray* = _root.main["camp"+i];
				_root.move = true;
				_root.xmov = 350;
				_root.ymov = 125;
				if (campSO.data.campsites == undefined) {
						campSO.data.campsites = new Object();
				}
 
				campSO = SharedObject.getLocal("campsite");
				CampSite.reserveCampSite(CampSite.campArray*);
		};
}
CampSite.main =function() {
		for (var i = 1; i<122; i++) {
				CampSite.doRelease(i);
		}
}
CampSite.main();

Wow! This has turned into a book, sorry. My movie is doing the same. I think I am overcomplicating things by adding more SO’s instead of correctly manageing the ones I have. I hopefully haven’t confused anyone that reads this as much as I have been in experimenting with this.

Thanks again for even looking.
Regards
NTD