Question

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
Was it helpful?

Solution

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

OTHER TIPS

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

Cheers, Drake Swartzy

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top