2014-04-16 61 views
0

在保存和正確加載一組背景圖像方面存在問題。請注意,這在過去使用caseSwapper中的「1 - 2」圖像正常工作。AS3 SharedObject - 背景圖像無法正確加載。存儲在MC內部的一組圖像無法從保存加載正確的圖像

結構: 在我的舞臺我已經設置拖動對象,你可以保存和加載,請你的。 (這些工作) 背景,這是movieClip所謂的「caseSwapper」包含一組幀在每個幀內的不同圖像。 E.G幀第一個被稱爲(標記)「frameone」 - 包含一個漂亮的圖片。幀2被標記爲「Frametwo」,其中包含的替換圖像等等等等

甲加載和保存在舞臺上的按鈕,可以將數據存儲到共享對象「mySO」

問題和行爲
在面對它,保存似乎正在工作。 trace語句聲明當前幀被存儲到mySO中,儘管我並不完全相信它。基本上,當玩家選擇了某個背景並點擊'保存'時,我需要將當前圖像保存/寫入共享對象。

注意:當我點擊舞臺上的「加載」時,第1幀顯示工作。當我'啓動'的應用程序(不加載),即使在保存幀123或4後,只有第4幀啓動/ DIS [奠定。然後我必須點擊加載來檢索我的sharedObject ...它只顯示第一幀...任何指針。編輯腳本位於底部。請注意,我首先是設計師!

save_btn.addEventListener (MouseEvent.CLICK, clickersave); 

function clickersave (e:MouseEvent):void { 
    saved.play(); 
mySO.data.myblcskull_mc_x = blcskull_mc.x; 
mySO.data.myblcskull_mc_y = blcskull_mc.y; 
mySO.data.myblackhandbag_mc_y = blackhandbag_mc.y; 
mySO.data.myblackhandbag_mc_x = blackhandbag_mc.x;  
mySO.data.myhotlips_mc_x = hotlips_mc.x; 
mySO.data.myhotlips_mc_y = hotlips_mc.y;  
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.myskullface_mc_y = skullface_mc.y; 
mySO.data.myskullface_mc_x = skullface_mc.x; 
mySO.data.myblack_tile_mc_zero_y = black_tile_mc_zero.y; 
mySO.data.myblack_tile_mc_zero_x = black_tile_mc_zero.x; 
mySO.data.myblack_tile_mc_one_x = black_tile_mc_one.x; 
mySO.data.myblack_tile_mc_one_y = black_tile_mc_one.y; 
mySO.data.mycrown_mc_y = crown_mc.y; 
mySO.data.mycrown_mc_x = crown_mc.x; 
mySO.data.myperfume_mc_y = perfume_mc.y; 
mySO.data.myperfume_mc_x = perfume_mc.x; 
mySO.data.myheart_mc_x = heart_mc.x; 
mySO.data.myheart_mc_y = heart_mc.y; 
mySO.data.myrose_mc_y = rose_mc.y; 
mySO.data.myrose_mc_x = rose_mc.x; 
// tears saved - - - - - - - 
mySO.data.mytear_drop_mc_one_x = tear_drop_mc_one.x; 
mySO.data.mytear_drop_mc_one_y = tear_drop_mc_one.y; 
mySO.data.mytearup_drop_mc_three_x = tearup_drop_mc_three.x; 
mySO.data.mytearup_drop_mc_three_y = tearup_drop_mc_three.y; 
mySO.data.mytearup_drop_mc_four_x = tearup_drop_mc_four.x; 
mySO.data.mytearup_drop_mc_four_y = tearup_drop_mc_four.y; 
mySO.data.mytear_drop_mc_two_x = tear_drop_mc.x; 
mySO.data.mytear_drop_mc_two_y = tear_drop_mc.y; 
mySO.data.mytear_side_mc_one_x = tear_side_mc_one.x; 
mySO.data.mytear_side_mc_one_y = tear_side_mc_one.y; 
mySO.data.mytear_side_mc_two_x = tear_side_mc_two.x; 
mySO.data.mytear_side_mc_two_y = tear_side_mc_two.y; 
mySO.data.mytear_op_mc_one_y = tear_op_mc_one.y; 
mySO.data.mytear_op_mc_one_x = tear_op_mc_one.x; 
mySO.data.mytear_op_mc_two_y = tear_op_mc_two.y; 
mySO.data.mytear_op_mc_two_x = tear_op_mc_two.x; 
//tear_op_mc_one 
// pink gems 
mySO.data.mypink_jewel_mc_one_x = pink_jewel_mc_one.x; 
mySO.data.mypink_jewel_mc_one_y = pink_jewel_mc_one.y; 
mySO.data.mypink_jewel_mc_two_x = pink_jewel_mc_two.x; 
mySO.data.mypink_jewel_mc_two_y = pink_jewel_mc_two.y; 
mySO.data.mypink_jewel_mc_three_x = pink_jewel_mc_three.x; 
mySO.data.mypink_jewel_mc_three_y = pink_jewel_mc_three.y; 
mySO.data.mypink_jewel_mc_four_x = pink_jewel_mc_four.x; 
mySO.data.mypink_jewel_mc_four_y = pink_jewel_mc_four.y; 
mySO.data.mypink_jewel_mc_five_x = pink_jewel_mc_five.x; 
mySO.data.mypink_jewel_mc_five_y = pink_jewel_mc_five.y; 
mySO.data.mypink_jewel_mc_six_x = pink_jewel_mc_six.x; 
mySO.data.mypink_jewel_mc_six_y = pink_jewel_mc_six.y; 
mySO.data.mypink_jewel_mc_seven_x = pink_jewel_mc_seven.x; 
mySO.data.mypink_jewel_mc_seven_y = pink_jewel_mc_seven.y; 
mySO.data.mypink_jewel_mc_eight_x = pink_jewel_mc_eight.x; 
mySO.data.mypink_jewel_mc_eight_y = pink_jewel_mc_eight.y; 
mySO.data.mypink_jewel_mc_nine_x = pink_jewel_mc_nine.x; 
mySO.data.mypink_jewel_mc_nine_y = pink_jewel_mc_nine.y; 
// bg saves 

mySO.data.myBgFrame = 1; 
mySO.data.myBgFrameone = 2; 
mySO.data.myBgFrametwo = 3; 
mySO.data.myBgFramethree = 4; 
trace("bgbackgrounds"); 

// silver gems - - - - - - - - - 
mySO.data.mycircle_gem_mc_x = circle_gem_mc.x; 
mySO.data.mycircle_gem_mc_y = circle_gem_mc.y; 
mySO.data.mycircle_gem_mc_two_x = circle_gem_mc_two.x; 
mySO.data.mycircle_gem_mc_two_y = circle_gem_mc_two.y; 
mySO.data.mycircle_gem_mc_thirteen_x = circle_gem_mc_thirteen.x; 
mySO.data.mycircle_gem_mc_thirteen_y = circle_gem_mc_thirteen.y; 
//circle_gem_mc_six 
mySO.flush(); 

} 

if (mySO.data.myBgFrame){ 
    caseSwapper.gotoAndStop(mySO.data.myBgFrame); 
} 
if (mySO.data.myBgFrameone){ 
    caseSwapper.gotoAndStop(mySO.data.myBgFrameone); 
} 
if (mySO.data.myBgFrametwo){ 
    caseSwapper.gotoAndStop(mySO.data.myBgFrametwo); 
} 
if (mySO.data.myBgFramethree){ 
    caseSwapper.gotoAndStop(mySO.data.myBgFramethree); 
} 

//caseSwapper.currentFrame = mySO.data.myBgFrame; 

/////// ---------------------- loader  

// ---------------------- LOADER ------------------------- 
//-------------------------------------------------------- 
//-------------------------------------------------------- 
// when load button is clicked it loads the x and y position of dragged objects pulled from the 
//sharedOject, it remembers the last var! 
load_btn.addEventListener (MouseEvent.CLICK, loadlast); 

function loadlast (e:MouseEvent):void { 
    //saved.play();  
caseSwapper.gotoAndStop(mySO.data.myBgFrame); 
//caseSwapper.currentFrame = mySO.data.myBgFrame; 
//caseSwapper.gotoAndStop(mySO.data.myBgFrameone); 
//caseSwapper.gotoAndStop(mySO.data.myBgFrametwo); 
//caseSwapper.gotoAndStop(mySO.data.myBgFramethree); 
//caseSwapper.gotoAndStop(mySO.data.myBgFramefour); 
blcskull_mc.x = mySO.data.myblcskull_mc_x; 
blcskull_mc.y = mySO.data.myblcskull_mc_y; 
blackhandbag_mc.y = mySO.data.myblackhandbag_mc_y; 
blackhandbag_mc.x = mySO.data.myblackhandbag_mc_x;  
bones_mc.x = mySO.data.my_x; 
bones_mc.y = mySO.data.my_y; 
tiger_mc.x = mySO.data.mytig_x; 
tiger_mc.y = mySO.data.mytig_y; 
btrfly_mc.x = mySO.data.mybut_x; 
btrfly_mc.y = mySO.data.mybut_y; 
crown_mc.x = mySO.data.mycrown_mc_x; 
crown_mc.y = mySO.data.mycrown_mc_y; 
perfume_mc.x = mySO.data.myperfume_mc_x; 
perfume_mc.y = mySO.data.myperfume_mc_y; 
heart_mc.x = mySO.data.myheart_mc_x; 
heart_mc.y = mySO.data.myheart_mc_y; 
rose_mc.y = mySO.data.myrose_mc_y; 
rose_mc.x = mySO.data.myrose_mc_x; 
pink_jewel_mc_one.x = mySO.data.mypink_jewel_mc_one_x; 
pink_jewel_mc_one.y = mySO.data.mypink_jewel_mc_one_y; 
pink_jewel_mc_two.x = mySO.data.mypink_jewel_mc_two_x; 
pink_jewel_mc_two.y = mySO.data.mypink_jewel_mc_two_y; 
pink_jewel_mc_three.x = mySO.data.mypink_jewel_mc_three_x; 
pink_jewel_mc_three.y = mySO.data.mypink_jewel_mc_three_y; 
pink_jewel_mc_four.x = mySO.data.mypink_jewel_mc_four_x; 
pink_jewel_mc_four.y = mySO.data.mypink_jewel_mc_four_y; 
pink_jewel_mc_five.x = mySO.data.mypink_jewel_mc_five_x; 
pink_jewel_mc_five.y = mySO.data.mypink_jewel_mc_five_y; 
pink_jewel_mc_six.x = mySO.data.mypink_jewel_mc_six_x; 
pink_jewel_mc_six.y = mySO.data.mypink_jewel_mc_six_y; 
pink_jewel_mc_seven.x = mySO.data.mypink_jewel_mc_seven_x; 
pink_jewel_mc_seven.y = mySO.data.mypink_jewel_mc_seven_y; 
pink_jewel_mc_eight.x = mySO.data.mypink_jewel_mc_eight_x; 
pink_jewel_mc_eight.y = mySO.data.mypink_jewel_mc_eight_y; 
pink_jewel_mc_nine.x = mySO.data.mypink_jewel_mc_nine_x; 
pink_jewel_mc_nine.y = mySO.data.mypink_jewel_mc_nine_y; 
hotlips_mc.x = mySO.data.myhotlips_mc_x; 
hotlips_mc.y = mySO.data.myhotlips_mc_y; 
tearup_drop_mc_three.y = mySO.data.mytearup_drop_mc_three_y; 
tearup_drop_mc_three.x = mySO.data.mytearup_drop_mc_three_x; 
tearup_drop_mc_four.x = mySO.data.mytearup_drop_mc_four_x; 
tearup_drop_mc_four.y = mySO.data.mytearup_drop_mc_four_y; 
tear_side_mc_one.x = mySO.data.mytear_side_mc_one_x; 
tear_side_mc_one.y = mySO.data.mytear_side_mc_one_y; 
//tear_side_mc_two.x = mySO.data.mytear_side_mc_two_x; 
//tear_side_mc_two.y = mySO.data.mytear_side_mc_two_y; 
tear_op_mc_one.y = mySO.data.mytear_op_mc_one_y; 
tear_op_mc_one.x = mySO.data.mytear_op_mc_one_x; 
tear_op_mc_two.y = mySO.data.mytear_op_mc_two_y; 
tear_op_mc_two.x = mySO.data.mytear_op_mc_two_x; 
//--- silver little gems ----------------- 
circle_gem_mc_thirteen.x = mySO.data.mycircle_gem_mc_thirteen_x; 
circle_gem_mc_thirteen.y = mySO.data.mycircle_gem_mc_thirteen_y; 
circle_gem_mc_two.x = mySO.data.mycircle_circle_gem_mc_two_x; 
circle_gem_mc_two.y = mySO.data.mycircle_circle_gem_mc_two_y; 
mySO.flush();  
} 

回答

1

你不是實際存儲當前幀的任何地方 - 這部分只是保存了相同的數字,每次:

mySO.data.myBgFrame = 1; 
mySO.data.myBgFrameone = 2; 
mySO.data.myBgFrametwo = 3; 
mySO.data.myBgFramethree = 4; 

這也是爲什麼你只看到幀中的四個當您啓動,因爲您的所有if語句都會看到一個正數(除零之外的任何數字或NaN都計爲true),因此它們都會一個接一個地執行。

代替上述的,你需要的是這在你的保存功能:如果你想跳就推出該幀

mySO.data.myBgFrame = caseSwapper.currentFrame; 

然後,你只需要你的第一個if聲明:

if (mySO.data.myBgFrame){ 
    caseSwapper.gotoAndStop(mySO.data.myBgFrame); 
} 
+0

謝謝大衛,我會在早上測試這個! – user3082874

+0

非常好!謝謝你的幫助。 「NaN」意味着什麼? – user3082874

+0

太棒了! NaN代表「不是數字」,如果您嘗試執行像'var result:Number = 0/0'這樣的操作,就會得到它。 –