A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: save & load state -drag&drop game

  1. #1
    Junior Member
    Join Date
    Feb 2008
    Posts
    15

    save & load state -drag&drop game

    Hello all,

    I'm having some trouble creating a save and load function so when I reload my drag&drop - duplicate items- application and click on load, I have my app with the last saved state. Could anyone help me out on this?

    Also, This is an exemple for 1 object, I need to use a bunch of objects to fill in the stage. I first had the idea of using a carousel i created once, but I didn't find out yet how to use a drag & drop/duplicate function on that one. In this example my var dupli is used for object1, and when i want an object 2 on stage to be duplicated I just copy the code of object 1..but that's not very "effective" when I need to put a hundred of different objects in my app a carousel with only one function to duplicate all of them would be better. Anyway, just this information aside since it could need a different approach for the save and load function, i don't know..?

    Code:
    //save & load
    
    var savefile = SharedObject.getLocal('rayon');
    
    
    //duplicate drag&drop for object1
    
    var mcNum = 1;
    var dupli:MovieClip;
    myobject1_mc.onPress = function() {
            dupli = myobject1_mc.duplicateMovieClip("myobject1_mc"+mcNum, ++mcNum);
            dupli._x = myobject1_mc._x;
            dupli._y = myobject1_mc._y;
            dupli.startDrag();
            this._parent["myobject1_mc"+mcNum].onPress = function() {
                this.startDrag();
            }
            this._parent["myobject1_mc"+mcNum].onRelease = function() {
                this.stopDrag();
            }
    };
    myobject1_mc.onRelease = function() {
            dupli.stopDrag();
    };
    myobject1_mc.onReleaseOutside = function() {
            dupli.stopDrag();
    };
    (on my save_mc movieclip)
    Code:
    save_mc.onPress = function() {//when the button is pressed
    savefile.data.dupli=_root.dupli;//save the variable dupli
    savefile.flush();//saves it as a cookie
    }
    (on my load_mc movieclip)
    Code:
    load_mc.onPress = function() {//when the button is pressed
    
    _root.level=savefile.data.dupli;//
    }

  2. #2
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    I didnt go through your code fully..

    I sorta remember the carousel post..but it looked like the carousel project form gotoAndLearn website..??

    anyways.. I have done his plenty of times for games/builder apps..etc

    I dont know you are setting up your project..

    but the general idea is..

    you need to have/keep a LIST of all objects on the stage (that you want to 'save/record')

    you do this by creating an array to hold all the info you want to save/record for each clip.. and storing it..

    ie: clip name
    xPos
    yPos
    _alpha
    color
    x & y scale
    depth

    etc

    etc whatever it is you'll need later to re-create & re-build this 'scenario'

    so on some button click (save)..

    you run through this list/array of objects, updating/recording all the unique data for each clip.. and save it..

    looks like your trying to use a SharedObject (flash cookie) to save the data locally on the users computer?


    FYI-
    depending on how much data there is to save..and the users specific security settings you may NOT be able to save anything at all..

  3. #3
    Junior Member
    Join Date
    Feb 2008
    Posts
    15
    well the carousel ain't the big issue, a basic scroll zone that I can fill with objects would be good enough, I just need to be able to use this drag&drop-duplicate on items inside a scrollable area/carousel, and later on save the state of what i put on stage while playing my swf. Gonna give a try on the drag drop first, if anyone could give me a hint on the save & load problem...?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center