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