简体   繁体   English

Flash Actionscript 3-简单的Btn单击保存游戏/应用

[英]Flash Actionscript 3 - Simple Btn Click save game/app

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" 这是一款精美的装扮游戏,用户游戏可以制作设计或艺术品,然后保存项目,然后单击“ 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. 我已经拖网了一些,找不到适合我的简单tut。

Code added, just in case. 添加代码,以防万一。

ps please keep it simple as I'm designer. ps,请保持简洁,因为我是设计师。 :-) :-)

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

Yeah, Atriace has the right idea. 是的,Atriace有正确的主意。 Check this out: http://www.republicofcode.com/tutorials/flash/as3sharedobject/ 检查一下: http : //www.republicofcode.com/tutorials/flash/as3sharedobject/

Cheers, Drake Swartzy 干杯,德雷克·斯瓦兹(Drake Swartzy)

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". 再次,该按钮的实例名称为“ 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 干杯,德雷克·斯瓦兹(Drake Swartzy)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM