1

I'm working on a project that requires me to save all of the bits and pieces on the second frame of the stage. This is a glorified dress up game where the user game make design or a piece of art and save the project and come back to it later by clicking the "restore_btn"

This will have multiple 'dragable' bits and pieces on the stage, on the second frame. Could someone give me some insight in how to make it so the app can save on the desktop and when the user opens it up and clicks the 'restore' button their last design loads up on the stage? Thanks for you help. I've had bit of trawl of the net and i can't find any simple tuts for what I need.

Code added, just in case.

p.s please keep it simple as I'm designer. :-)

stop();

Mouse.hide();
stage.addEventListener(MouseEvent.MOUSE_MOVE,follow);
function follow(evt:MouseEvent){
    tweezer_cur.x = mouseX;
    tweezer_cur.y = mouseY;
}

//Resetter btn ---------------------

reset_btn.addEventListener(MouseEvent.CLICK, startover);

function startover(event:MouseEvent):void
{
gotoAndPlay(1);
}

//------------------------------ fullscreen
function setFullScreen():void {
if (stage.displayState== "normal") {
stage.displayState="fullScreen";
stage.scaleMode = StageScaleMode.NO_SCALE;
} else {
stage.displayState="normal";
 }
}

fullbtn.addEventListener(MouseEvent.CLICK, goFull); 
        // btn declared - - - - - - - - 

        function goFull(event:MouseEvent):void {
setFullScreen();
};

//---------------------------- print project


//--- all the draggables will live here
dragme.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
dragme.addEventListener(MouseEvent.MOUSE_UP, dropObject);

function pickupObject(event:MouseEvent):void {
event.target.startDrag(true);
}
function dropObject(event:MouseEvent):void {
event.target.stopDrag();
}


//--------

//creating a container as main canvas

var artworkContainers:Sprite = new Sprite();
addChild(artworkContainers);

//example adding content
//var anyContentIWantToPrint:Sprite = new Sprite();
//anyContentIWantToPrint.graphics.beginFill(0, 1);
//anyContentIWantToPrint.graphics.drawRect(0, 0, 1024, 768);
//anyContentIWantToPrint.graphics.endFill();
//artworkContainers.addChild(anyContentIWantToPrint);

printme_btn.addEventListener(MouseEvent.CLICK, startPrintJobHandler, false, 0, true);

function startPrintJobHandler(event:MouseEvent):void
{
     var printJob:PrintJob = new PrintJob();
     printJob.start()

     var printJobOptions:PrintJobOptions = new PrintJobOptions(); 
     printJobOptions.printAsBitmap = true; 
     //When 'artworkContainer' will be your artwork canvas, where the user will drag and drop.   Replace for the instance name you are using.     
     printJob.addPage(artworkContainers, null, printJobOptions);

     printJob.send();
  }

 // making all of the functions save! --------------------------------

var saveData:SharedObject = SharedObject.getLocal("MyDesign");

 if(!saveData.data.test)
     saveData.data.test = "Test string";
    trace(saveData.data.test); // Test string
user3082874
  • 61
  • 2
  • 11
  • Well. Seems you are able to save stuff. Are you able to retrieve it? After that you need to put everything on your stage with the information you have saved. It won't be simple I'm afraid. – putvande Jan 08 '14 at 10:38
  • lol, sounds tricky? There's a button I have set to the stage that I want to assign to the restore function later on , called... "restore_btn" any clues? will I need to make it store the data of the x and y or each and every single movieclip? I was hoping there would be a way of saving it in all of it's entirety in one hit? Thanks, – user3082874 Jan 08 '14 at 12:32
  • 1
    Depends on your design, but ultimately it's a case of saving each clip's coordinates and applying them after restore. Loop through your `SharedObject` and match'em up to your stage items. – Atriace Jan 08 '14 at 15:05
  • Hello thank you for the heads up. I will have a look when I get the time. I might be back an forth to here as I'm new to AS3 and... i have never had the need to use save functions :-) – user3082874 Jan 09 '14 at 09:19

2 Answers2

1

Yeah, Atriace has the right idea. Check this out: http://www.republicofcode.com/tutorials/flash/as3sharedobject/

Cheers, Drake Swartzy

DrakeTruber
  • 327
  • 1
  • 6
  • 21
  • Hello Drake, thanks for sending the tut over... the only thing is When I click refresh - the clips weren't where I'd left them. The thing reset itself? :-) Anyway, will this methodology work with local as well? Cheers, I will have a play when I get the time. Regards, Jim – user3082874 Jan 09 '14 at 09:23
  • Hello Drake, thank you for pointing that tut to me. For some reason it worked after 3 hours and i followed the tut. It's great, I have even attached it the sharedOject to a mouse event (save_btn) Thanks again. Now all i have to do is work out how to make it restore the last save. – user3082874 Jan 09 '14 at 14:20
  • Awesome @user3082874! Sorry for the late response. I'm glad that tutorial helps. If you have anymore questions just ask! – DrakeTruber Jan 10 '14 at 01:01
  • Yeah I was very good - impressed. :-) Any clues on how to make it restore? – user3082874 Jan 10 '14 at 09:42
1

This is too long to answer in a comment, so here it goes:

import flash.net.SharedObject;
import flash.geom.Point;
import flash.events.MouseEvent;

var restore_values:SharedObject=SharedObject.getLocal("dress_up_game");

if(!restore_values.data.shirt_point){
    restore_values.data.shirt_point=new Point(shirt.x,shirt.y);
    restore_values.flush();
}

restore_btn.addEventListener(MouseEvent.CLICK,restore);
function restore(e:MouseEvent){
    if(restore_values.data.shirt_point){
        shirt.x=restore_values.data.shirt_point.x;
        shirt.y=restore_values.data.shirt_point.y;
    }
}

shirt.addEventListener(MouseEvent.MOUSE_DOWN,start_shirt_drag);
function start_shirt_drag(e:MouseEvent){
    shirt.startDrag()


}
shirt.addEventListener(MouseEvent.MOUSE_UP,stop_shirt_drag);
function stop_shirt_drag(e:MouseEvent){
    shirt.stopDrag()
    restore_values.data.shirt_point=new Point(shirt.x,shirt.y);
    restore_values.flush();
}

It took me a few minutes to scratch this out. Once again, the button's instance name is "restore_btn". The garment or "draggable bit" goes by the instance name "shirt". The code places the shirt at the last saved position if you click the restore button. You should be able to adapt this code to your project's situation on your own.

Cheers, Drake Swartzy

DrakeTruber
  • 327
  • 1
  • 6
  • 21
  • 1
    Great! I will have a look. I will need to tailor this to fit in with the rest of my code with names etc. I was wander though, will var restore_values:SharedObject=SharedObject.getLocal("dress_up_game"); Have a conflict with my save shared object? var saveData:SharedObject = SharedObject.getLocal("MyDesign"); Cheers, – user3082874 Jan 13 '14 at 15:19
  • Yeah, good point. Just store all the data you need under one shared object. – DrakeTruber Jan 15 '14 at 20:16
  • Hello Drake, just spotted another thing. Have you attached it so that the restore function is tied into the stopDrag function of the shirt? or is it just storing the data - if so, I have a save btn... will this override that? – user3082874 Jan 22 '14 at 17:28
  • I apologize for the late reply. If you want to create both a save button and load button you will have to rework the code. This code saves it for every release. – DrakeTruber Jan 30 '14 at 23:59
  • Hello Drake, no worries. I have sussed out a reset_btn work around instead. So when the user clicks the button it takes you back to frame 2 (all the main code is frame 3) it just bypasses the save function and reloads the stage if that makes sense? It is as crude and as simple as it sounds. Although if you have any pointers for a speedy save and load functionality I'm happy to listen. – user3082874 Jan 31 '14 at 09:31
  • although whatever works works, your code could be a lot cleaner and efficient if you use as single frame of code instead of maneuvering from frame code to frame code. However, I don't have a better sense of your situation than you do, so if you think that method suits your project best than go for it! – DrakeTruber Feb 03 '14 at 20:06
  • Hello, Indeed. I need to get more into the habit of using the classes for making the whole construct. But on the face of it, it works well and I wont complain at the min. Cheers, – user3082874 Feb 04 '14 at 10:04
  • 1
    Handy info for making the load function work, the opposite to save. bones_mc.x = mySO.data.my_x; bones_mc.y = mySO.data.my_y; – user3082874 Mar 07 '14 at 12:33