2017-08-28 55 views
0

這裏好像什麼它應該做的事:按鈕在ActionScript 3.0工作了

  1. 有一個啓動按鈕,並在主屏幕恢復按鈕。
  2. 隨着畫面的進展,還有一個「保存進度&返回主頁」按鈕,它將保存當前畫面並返回到主屏幕。
  3. 回到主屏幕,當您點擊「簡歷」時,它會將 帶回到您之前的圖片中。
  4. And ...等等等等。

我做了1-3。但是當它返回到前一幀時,按鈕似乎不再起作用。就像,你無法繼續前進並移動幀。

這裏的一個屏幕截圖: screenshot

然後,這裏有兩個以上的動作腳本代碼:

1幀:

stop(); 

start_btn.addEventListener(MouseEvent.CLICK, gotoIntro); 

function gotoIntro(event:MouseEvent):void 
{ 
    gotoAndStop('intro'); 
} 

resume_btn.addEventListener(MouseEvent.CLICK, gotoLastFrame); 

function gotoLastFrame(event:MouseEvent):void 
{ 
    gotoAndStop(lastFrame); 
    trace(currentFrame); 
} 

2幀:

var lastFrame:int = currentFrame; 

next_btn.addEventListener(MouseEvent.CLICK, gotoNext); 

function gotoNext(event:MouseEvent):void 
{ 
    nextFrame(); 
    lastFrame++; 
    trace("current frame: " + currentFrame + "; saved frame: " + lastFrame); 

} 

back_btn.addEventListener(MouseEvent.CLICK, gotoHome); 

function gotoHome(event:MouseEvent):void 
{ 
    gotoAndStop('home'); 
    trace(lastFrame); 
} 

這是一個未來簡單的視覺小說,我會喜歡在未來做出。但哈哈我已經卡在這裏哈哈哈。有人可以幫助如何再次向前移動框架嗎?非常感謝!

回答

1

問題是你的幀。幀總是很難管理。當你轉到第2幀時,事件監聽器被添加到你的下一步按鈕。當你然後去第3幀,然後離開第1幀,你的按鈕就從舞臺上移開。當你回到第3幀時,一個新的「下一個」按鈕被添加到舞臺上,但是沒有事件監聽器(因爲你已經跳過第2幀)。

一個簡單的解決方案是將您的小說框架與代碼一起移動到自己的動畫片段中,並將其稱爲「myNovel」作爲實例名稱。將您的開始屏幕移動到另一個動畫片段並稱爲「myStartScreen」。他們兩人都在第一幀的舞臺上,但你的小說是看不見的。其實你只需要一個框架在你的主要時間線上

然後當你點擊開始或下一步時,你的開始屏幕不可見並且你的小說可見。你甚至不需要記住框架,因爲它會留在你離開的框架中。

主時間軸代碼:

// make novel invisible at the beginning 
myNovel.visible = false; 

function gotoHome():void 
{ 
    // the novel will stay in the current frame 
    myStartScreen.visible = true; 
    myNovel.visible = false; 
} 

// startFromTheBeginning is an optional parameter 
function gotoNovel(startFromTheBeginning:Boolean = false):void 
{ 
    // the novel will stay in the current frame 
    myStartScreen.visible = false; 
    myNovel.visible = true; 

    if(startFromTheBeginning) 
    { 
     myNovel.gotoAndStop(1); 
    } 
} 

開始屏幕代碼:

start_btn.addEventListener(MouseEvent.CLICK, gotoIntro); 

function gotoIntro(event:MouseEvent):void 
{ 
    // parent is the parent moveiclip (your main timeline with the code above) 
    parent.gotoNovel(true); // start from the beginning 
} 

resume_btn.addEventListener(MouseEvent.CLICK, gotoLastFrame); 

function gotoLastFrame(event:MouseEvent):void 
{ 
    parent.gotoNovel(); // this will make the novel visible that are in the frame that the user left 
} 

新代碼

next_btn.addEventListener(MouseEvent.CLICK, gotoNext); 

function gotoNext(event:MouseEvent):void 
{ 
    nextFrame(); 
} 

back_btn.addEventListener(MouseEvent.CLICK, gotoHome); 

function gotoHome(event:MouseEvent):void 
{ 
    parent.gotoHome(); 
} 
+0

哇,我認爲這將是一個好主意,把雙方的開始和小說在兩個不同的電影剪輯。我甚至沒有想到:D謝謝!但是,在這種情況下,我如何獲得可以返回到啓動屏幕的功能,並且當我在啓動屏幕上點擊「恢復按鈕」時,我可以回到最後一幀我在? –

+0

重讀我的評論 - 「開始屏幕代碼」應該在strtscreen movieclip和「Novel code」中 - 在新穎的動畫片段中。該代碼正在調用主時間軸上的函數 – Philarmon

相關問題