PDA

View Full Version : Shard Object Problems


Fergal
01-18-2007, 09:22 PM
I am trying to add in a shared object so that I can save and load the game from a local computer. I have followed a tutorial on Kirupa tutorials section but my expierence with this is limited. Can anyone help me out with this night mare of a problem.

I have added in the action script so you can get a better understanding of what i am trying to accomplish.

Thanks in advance for any help.

Fergal

I have also added a link to the SWF so you can see how the game works. Click Here (http://www.mcatee.co.uk/test/Pick53_11.swf)

The FLA is also available on request.

fscommand("fullscreen", true);
fscommand("allowscale", false);
fscommand("showmenu", false);

// setup our variables
var count = 0; // count variable
var xp = 125; // starting _x position (horizontal)
var yp = 160; // starting _y position (vertical)
var vs = 10; // vertical space between cards
var hs = 10; // horizontal space between cards
var rows = 6; // how many rows?
var cols = 9; // how many columns?
var mc = null; // refrence current movieclip
var deck = []; // list all the playable cards

//Shared Object which enables a save and load through the use of a button
user_so = SharedObject.getLocal("user");
user_so.data.FindtheJoker = _root.FindtheJoker;
user_so.data.FindtheJoker;

_root.saveBtn.onRelease = function(){
user_so = SharedObject.getLocal("user");
user_so.data.FindtheJoker = _root.FindtheJoker;
}
_root.loadBtn.onRelease = function(){
user_so = SharedObject.getLocal("user");
if (user_so.data.FindtheJoker != undefined) {
FindtheJoker = user_so.data.FindtheJoker;
} else {
FindtheJoker = 100;
}
}

// function used to shuffle the deck of cards
function shuffle() { return Math.floor(Math.random() * 2) }

// initiate our stage
function initStage() {
// list all available cards (linkage identifier)
var spades = ['2S','3S','4S','5S','6S','7S','8S','9S','10S','JS' ,'QS','KS','AS'];
var clubs = ['2C','3C','4C','5C','6C','7C','8C','9C','10C','JC' ,'QC','KC','AC'];
var hearts = ['2H','3H','4H','5H','6H','7H','8H','9H','10H','JH' ,'QH','KH','AH'];
var diamonds = ['2D','3D','4D','5D','6D','7D','8D','9D','10D','JD' ,'QD','KD','AD'];
var dummy = ['DMY'];

// list our deck of cards
deck = spades.concat(clubs, hearts, diamonds, dummy);

// add our winning card
deck.push('YW');

// shuffle the deck around
deck.sort(shuffle);

// attach cards from our library
for (var i = 0; i < rows; i++) {
for (var j = 0; j < cols; j++) {
// attach and resize the current cards
// but first check if its one of the winning cards
if (deck[count] == 'YW') {
// give it a unique number at the end of its instance name
mc = attachMovie(deck[count], deck[count] + count, count, {_xscale:40, _yscale:40});
// replace YW with its new name
deck[count] = deck[count] + count;
} else {
// keep the same name used in the array
mc = attachMovie(deck[count], deck[count], count, {_xscale:40, _yscale:40});
}

// create movieclip where we'll place a number to identify its order
mc.createEmptyMovieClip('txt_mc', mc.getNextHighestDepth());

// create a textfield inside that movieclip & refrence it with variable _txt
var _txt = mc.txt_mc.createTextField('txt', 0, -45, -30, 50, 50);
_txt.autoSize = true
_txt.text = count + 1;

// create a textformat for our textfield & refrence it with variable _fmt
var _fmt:TextFormat = new TextFormat();
_fmt.bold = true;
_fmt.align = 'center';
_fmt.font = 'Veranda';
_fmt.size = 100;
_fmt.color = 0xFF0000;

// apply the textformat to the textfield
_txt.setTextFormat(_fmt);

// position the cards
mc._x = xp + (mc._width + hs) * j;
mc._y = yp + (mc._height + vs) * i;

// give the cards a button handler
mc.onPress = function () {
this.enabled = false; // disable the card's button handler
this.gotoAndPlay(2); // play its timeline
this.txt_mc.txt.text = '';
switch (this._name) {
case 'JS':
case 'JH':
case 'JD':
case 'JC':

var showGood=true;
break;
}
if (showGood==true) {
attachMovie('try_againJ_mc', 'try_againJ_mc', 100000);
try_againJ_mc.try_again_btn.onRelease=function () {
removeMovieClip(this._parent);
}
return;
} else {
removeMovieClip(_root.congrats);
}


this.txt_mc.txt.text = '';
switch (this._name) {

case 'QS':
case 'QH':
case 'QD':
case 'QC':

var showGood=true;
break;
}
if (showGood==true) {
attachMovie('try_againQ_mc', 'try_againQ_mc', 100000);
try_againQ_mc.try_again_btn.onRelease=function () {
removeMovieClip(this._parent);
}
return;
} else {
removeMovieClip(_root.congrats);
}
this.txt_mc.txt.text = '';
switch (this._name) {

case 'KS':
case 'KH':
case 'KD':
case 'KC':

var showGood=true;
break;
}
if (showGood==true) {
attachMovie('try_againK_mc', 'try_againK_mc', 100000);
try_againK_mc.try_again_btn.onRelease=function () {
removeMovieClip(this._parent);
}
return;
} else {
removeMovieClip(_root.congrats);
}
this.txt_mc.txt.text = '';
switch (this._name) {

case 'AS':
case 'AH':
case 'AD':
case 'AC':

var showGood=true;
break;
}
if (showGood==true) {
attachMovie('try_againA_mc', 'try_againA_mc', 100000);
try_againA_mc.try_again_btn.onRelease=function () {
removeMovieClip(this._parent);
}
return;
} else {
removeMovieClip(_root.congrats);
}
this.txt_mc.txt.text = '';
switch (this._name) {

case 'DMY':

var showGood=true;
break;
}
if (showGood==true) {
attachMovie('try_againD_mc', 'try_againD_mc', 100000);
try_againD_mc.try_again_btn.onRelease=function () {
removeMovieClip(this._parent);
}
return;
} else {
removeMovieClip(_root.congrats);
}

checkCard(this._name); // call function & pass its name
}
// increase variable
count++;
}
}
}

function checkCard(card) {
// is it the winning cards?
if (card.slice(0,2) == 'YW') {
// disable all the cards
for (mc in this) { // search through every object on our timeline
if (typeof(this[mc]) == 'movieclip') { // if current object is a movieclip
this[mc].enabled = false; // disable its button hanlder
}
}

// create a delay
var si = setInterval(function() {
// when day is over clear the interval function
clearInterval(si);

// attach our congrats screen
_root.attachMovie('congrats', 'congrats', _root.getNextHighestDepth());

// add button handler to our play again movieclip
congrats.congrats_btn.onPress = function () {
// clear the board
for (mc in _root) { // search through every object on our timeline
if (typeof(_root[mc]) == 'movieclip') { // if current object is a movieclip
_root[mc].removeMovieClip(); // remove it from the stage
}
}

// shuffle the deck of cards again
deck.sort(shuffle);

// revert count variable
count = 0;

// initiate the stage again
initStage();
}
}, 500); // how long is the delay?
}
}

// start game
initStage();

newblack
01-18-2007, 09:35 PM
user_so = SharedObject.getLocal("user");
user_so.data.FindtheJoker = _root.FindtheJoker;
user_so.data.FindtheJoker;
This is defining the SharedObject as _root.FindtheJoker- when the user presses the load button, no saved data can be loaded because you're already replaced it with the new FindtheJoker object

Fergal
01-22-2007, 09:42 AM
Ahh I see. Thanks man. How can I fix this? Can you please help!!!?

Fergal
03-08-2007, 09:40 PM
I am trying to add in a shared object so that I can save and load the game from a local computer. I have followed a tutorial on Kirupa tutorials section but my expierence with this is limited. Can anyone help me out with this night mare of a problem.

I have added in the action script so you can get a better understanding of what i am trying to accomplish.

Thanks in advance for any help.

Fergal

I have also added a link to the SWF so you can see how the game works. Click Here (http://www.mcatee.co.uk/test/Pick53_11.swf)

The FLA is also available on request.

fscommand("fullscreen", true);
fscommand("allowscale", false);
fscommand("showmenu", false);

// setup our variables
var count = 0; // count variable
var xp = 125; // starting _x position (horizontal)
var yp = 160; // starting _y position (vertical)
var vs = 10; // vertical space between cards
var hs = 10; // horizontal space between cards
var rows = 6; // how many rows?
var cols = 9; // how many columns?
var mc = null; // refrence current movieclip
var deck = []; // list all the playable cards

//Shared Object which enables a save and load through the use of a button
user_so = SharedObject.getLocal("user");
user_so.data.FindtheJoker = _root.FindtheJoker;
user_so.data.FindtheJoker;

_root.saveBtn.onRelease = function(){
user_so = SharedObject.getLocal("user");
user_so.data.FindtheJoker = _root.FindtheJoker;
}
_root.loadBtn.onRelease = function(){
user_so = SharedObject.getLocal("user");
if (user_so.data.FindtheJoker != undefined) {
FindtheJoker = user_so.data.FindtheJoker;
} else {
FindtheJoker = 100;
}
}

// function used to shuffle the deck of cards
function shuffle() { return Math.floor(Math.random() * 2) }

// initiate our stage
function initStage() {
// list all available cards (linkage identifier)
var spades = ['2S','3S','4S','5S','6S','7S','8S','9S','10S','JS' ,'QS','KS','AS'];
var clubs = ['2C','3C','4C','5C','6C','7C','8C','9C','10C','JC' ,'QC','KC','AC'];
var hearts = ['2H','3H','4H','5H','6H','7H','8H','9H','10H','JH' ,'QH','KH','AH'];
var diamonds = ['2D','3D','4D','5D','6D','7D','8D','9D','10D','JD' ,'QD','KD','AD'];
var dummy = ['DMY'];

// list our deck of cards
deck = spades.concat(clubs, hearts, diamonds, dummy);

// add our winning card
deck.push('YW');

// shuffle the deck around
deck.sort(shuffle);

// attach cards from our library
for (var i = 0; i < rows; i++) {
for (var j = 0; j < cols; j++) {
// attach and resize the current cards
// but first check if its one of the winning cards
if (deck[count] == 'YW') {
// give it a unique number at the end of its instance name
mc = attachMovie(deck[count], deck[count] + count, count, {_xscale:40, _yscale:40});
// replace YW with its new name
deck[count] = deck[count] + count;
} else {
// keep the same name used in the array
mc = attachMovie(deck[count], deck[count], count, {_xscale:40, _yscale:40});
}

// create movieclip where we'll place a number to identify its order
mc.createEmptyMovieClip('txt_mc', mc.getNextHighestDepth());

// create a textfield inside that movieclip & refrence it with variable _txt
var _txt = mc.txt_mc.createTextField('txt', 0, -45, -30, 50, 50);
_txt.autoSize = true
_txt.text = count + 1;

// create a textformat for our textfield & refrence it with variable _fmt
var _fmt:TextFormat = new TextFormat();
_fmt.bold = true;
_fmt.align = 'center';
_fmt.font = 'Veranda';
_fmt.size = 100;
_fmt.color = 0xFF0000;

// apply the textformat to the textfield
_txt.setTextFormat(_fmt);

// position the cards
mc._x = xp + (mc._width + hs) * j;
mc._y = yp + (mc._height + vs) * i;

// give the cards a button handler
mc.onPress = function () {
this.enabled = false; // disable the card's button handler
this.gotoAndPlay(2); // play its timeline
this.txt_mc.txt.text = '';
switch (this._name) {
case 'JS':
case 'JH':
case 'JD':
case 'JC':

var showGood=true;
break;
}
if (showGood==true) {
attachMovie('try_againJ_mc', 'try_againJ_mc', 100000);
try_againJ_mc.try_again_btn.onRelease=function () {
removeMovieClip(this._parent);
}
return;
} else {
removeMovieClip(_root.congrats);
}


this.txt_mc.txt.text = '';
switch (this._name) {

case 'QS':
case 'QH':
case 'QD':
case 'QC':

var showGood=true;
break;
}
if (showGood==true) {
attachMovie('try_againQ_mc', 'try_againQ_mc', 100000);
try_againQ_mc.try_again_btn.onRelease=function () {
removeMovieClip(this._parent);
}
return;
} else {
removeMovieClip(_root.congrats);
}
this.txt_mc.txt.text = '';
switch (this._name) {

case 'KS':
case 'KH':
case 'KD':
case 'KC':

var showGood=true;
break;
}
if (showGood==true) {
attachMovie('try_againK_mc', 'try_againK_mc', 100000);
try_againK_mc.try_again_btn.onRelease=function () {
removeMovieClip(this._parent);
}
return;
} else {
removeMovieClip(_root.congrats);
}
this.txt_mc.txt.text = '';
switch (this._name) {

case 'AS':
case 'AH':
case 'AD':
case 'AC':

var showGood=true;
break;
}
if (showGood==true) {
attachMovie('try_againA_mc', 'try_againA_mc', 100000);
try_againA_mc.try_again_btn.onRelease=function () {
removeMovieClip(this._parent);
}
return;
} else {
removeMovieClip(_root.congrats);
}
this.txt_mc.txt.text = '';
switch (this._name) {

case 'DMY':

var showGood=true;
break;
}
if (showGood==true) {
attachMovie('try_againD_mc', 'try_againD_mc', 100000);
try_againD_mc.try_again_btn.onRelease=function () {
removeMovieClip(this._parent);
}
return;
} else {
removeMovieClip(_root.congrats);
}

checkCard(this._name); // call function & pass its name
}
// increase variable
count++;
}
}
}

function checkCard(card) {
// is it the winning cards?
if (card.slice(0,2) == 'YW') {
// disable all the cards
for (mc in this) { // search through every object on our timeline
if (typeof(this[mc]) == 'movieclip') { // if current object is a movieclip
this[mc].enabled = false; // disable its button hanlder
}
}

// create a delay
var si = setInterval(function() {
// when day is over clear the interval function
clearInterval(si);

// attach our congrats screen
_root.attachMovie('congrats', 'congrats', _root.getNextHighestDepth());

// add button handler to our play again movieclip
congrats.congrats_btn.onPress = function () {
// clear the board
for (mc in _root) { // search through every object on our timeline
if (typeof(_root[mc]) == 'movieclip') { // if current object is a movieclip
_root[mc].removeMovieClip(); // remove it from the stage
}
}

// shuffle the deck of cards again
deck.sort(shuffle);

// revert count variable
count = 0;

// initiate the stage again
initStage();
}
}, 500); // how long is the delay?
}
}

// start game
initStage();

jsonchiu
03-22-2007, 01:18 AM
you need to call the flush() function in order for it to be saved.
_root.saveBtn.onRelease = function(){
user_so = SharedObject.getLocal("user");
user_so.data.FindtheJoker = _root.FindtheJoker;
user_so.flush();
}
_root.loadBtn.onRelease = function(){
user_so = SharedObject.getLocal("user");
if (user_so.data.FindtheJoker != undefined) {
_root.FindtheJoker = user_so.data.FindtheJoker;
} else {
_root.FindtheJoker = 100;
}
}

Fergal
03-22-2007, 04:31 PM
jsonchiu,

Thanks for your help, I have tried your piece of code, but I am still having problems with it. aaaaaggghh

If you wouldn't mind, perhaps you could take a look at the FLA for me, probably something that I have done caused it. lol

FLA (http://www.mcatee.co.uk/test/wantthefla/Pick53_11.fla)

Would be very greatful.

Fergal

jsonchiu
03-24-2007, 05:32 PM
urr.... How am i supposed to help you? What's the variable "FindTheJoker" used for? It only appear 3 times, and that's inside those buttons. It has no effect on the cards. Got that?

Fergal
03-29-2007, 11:36 AM
Sorry man, I don't know if thats the right variable to be using. I have never work with shared object before. Really don't have a notion about it. I am just so confuesd about the whole thing.