我在通过AS3笨手笨脚的时候我又回到了想要能够从sharedObject加载我的上一次保存的想法。任何帮助将不胜感激,因为我仍然是AS3的新手。 我也想把它附加到负载btn。
// SAVE FUNCTIONS ---------------------------------------
//---------------------------------------------------
//---------------------------------------------------
var mySO:SharedObject = SharedObject.getLocal("iDesign");
bones_mc.x = mySO.data.my_x;
bones_mc.y = mySO.data.my_y;
if (!mySO.data.my_y) {
bones_mc.x = 424;
bones_mc.y = 119;
}
//---- THIS IS THE SAVER BTN
save_btn.addEventListener (MouseEvent.CLICK, clickersave);
function clickersave (e:MouseEvent):void {
mySO.data.my_x = bones_mc.x;
mySO.data.my_y = bones_mc.y;
mySO.data.mybut_x = btrfly_mc.x;
mySO.data.mybut_y = btrfly_mc.y;
mySO.data.mytig_x = tiger_mc.x;
mySO.data.mytig_y = tiger_mc.y;
mySO.data.mybow_x = pink_bow_mc.x;
mySO.data.mybow_y = pink_bow_mc.y;
mySO.flush ();
}
//----
bones_mc.buttonMode=true;
btrfly_mc.x = mySO.data.mybut_x;
btrfly_mc.y = mySO.data.mybut_y;
if (!mySO.data.mybut_y) {
btrfly_mc.x = 112;
btrfly_mc.y = 295;
}
btrfly_mc.buttonMode=true;
tiger_mc.x = mySO.data.mytig_x;
tiger_mc.y = mySO.data.mytig_y;
if (!mySO.data.mytig_y) {
tiger_mc.x = 804;
tiger_mc.y = 411;
}
tiger_mc.buttonMode=true;
pink_bow_mc.x = mySO.data.mybow_x;
pink_bow_mc.y = mySO.data.mybow_y;
if (!mySO.data.mybow_y) {
pink_bow_mc.x = 923;
pink_bow_mc.y = 579;
}
load_btn.addEventListener (MouseEvent.CLICK, loadlast);
function loadlast (e:MouseEvent):void {
bones_mc.x = mySO.data.my_x;
bones_mc.y = mySO.data.my_y
//mySO.data.mybut_x = btrfly_mc.x;
//mySO.data.mybut_y = btrfly_mc.y;
//mySO.data.mytig_x = tiger_mc.x;
//mySO.data.mytig_y = tiger_mc.y;
//mySO.data.mybow_x = pink_bow_mc.x;
//mySO.data.mybow_y = pink_bow_mc.y;
mySO.flush ();
}
答案 0 :(得分:0)
当我想检查某人正在玩的游戏是否有Flash Cookie时,我声明了_cookiesActive:Boolean并使用以下代码:
try {
so = SharedObject.getLocal("savedData");
_cookiesActive = true;
} catch (error) {
_cookiesActive = false;
};
然后,如果_cookiesActive == true,您可以访问so.data以及您上次玩游戏时可能设置的任何变量,即:
bones_mc.x = so.data.my_x;
bones_mc.y = so.data.my_y;
..等等。
顺便说一句,上面示例中注释掉的代码将SAVE变量保存到SharedObject,而不是加载它们。所以你已经有了代码来保存它们。
正如你所建议的那样,按一下按钮点击加载它们只是让代码将变量从SharedObject传递到CLICK的处理函数中的游戏变量。