LOADING
Loading
Hi , welcome back.
LogoutLOGOUT
 
  Lost password?  
Hi
 


Prev Previous Post   Next Post Next
  #1  
Old 10-22-2006, 09:18 PM
fergal fergal is offline
Registered User
 
Join Date: Jul 2006
Posts: 7
Rep Power: 0
fergal is on a distinguished road
Shared Object Problems

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.com but I still don't have a clue about it.

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

PHP Code:

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(clubsheartsdiamondsdummy);
    
    
// add our winning card
    
deck.push('YW');
    
    
// shuffle the deck around
    
deck.sort(shuffle);
    
    
// attach cards from our library
    
for (var 0rowsi++)  {
        for (var 
0colsj++) {
            
// 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] + countcount, {_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, -305050); 
            
_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(); 
Reply With Quote
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Runtime Shared Libraries Bromid Flash CS3 / Flash 9 7 02-14-2008 03:26 PM
Score Boards using shared object class jehst Newbies 0 12-24-2007 11:18 PM
Can javascript or PHP write directly to a shared object? cronoklee General Flash 0 11-10-2006 05:01 PM
XML in shared object worthyashs XML & Sockets 0 08-29-2005 09:02 PM
Local Object Storage Path Problems limitedwave Flash MX 6 07-17-2004 03:56 AM




All times are GMT. The time now is 11:29 AM.