0
我笨拙的通過AS3的方式我已經回到想要能夠加載我從sharedObject上次保存的想法。任何幫助將不勝感激,因爲我仍然是AS3的新手。 我也想將它附加到加載BTN。AS3 sharedObject - 如何加載我的最後一個共享對象上btnCLICK
// 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();
}
嘿,感謝額外的頭幫助。當我有機會時,我將不得不放棄它。 – user3082874
嗯,我試圖剪切並粘貼上面的代碼片段,修改「so」到mySO和「savedDate」,它回退了未定義屬性的錯誤。因此,爲了使代碼在上面激活(註釋掉的代碼),我如何獲得load_btn來工作並調用sharedObject?對不起,我慢一點。 。 。 。 – user3082874
也許我應該說 - 你需要導入flash.net.SharedObject;在我們的類的開始處,並且在你的變量定義中,你將需要聲明'so'作爲一個SharedObject,即private var so:SharedObject;請注意,so = SharedObject.getLocal(「sharedData」)將調用SharedObject類上的靜態方法'getLocal'; THAT返回一個SharedObject對象。因此,您不需要以常規方式實例化一個SharedObject(即so = new SharedObject())。 – moosefetcher