2017-10-20 427 views
1

在有生命的CC,(動作3)我有需要按順序去當「A」或「d」按鈕被按下等,從而4個幀:的Actionscript導航不工作

(((((1- - > 2 - > 3 - > 4 |||然後返回||| 4 - > 3 - > 2 - > 1)))))

這工作正常,但當我回到第1幀後上述順序,點擊下一個將我所有的幀4的方式(使用跟蹤我確定所有的事件監聽器觸發的,我不知道爲什麼)

下面是每一幀代碼:

1幀

stage.addEventListener(KeyboardEvent.KEY_DOWN, nextFram); 
 
function nextFram(e:KeyboardEvent):void{ 
 
if (currentLabel == "home" && e.keyCode == Keyboard.D){ 
 
\t trace("gotobuttonpage"); 
 
\t gotoAndPlay("buttonPage"); 
 
\t removeEventListener(KeyboardEvent.KEY_DOWN, nextFram); 
 
\t trace("event listener removed"); 
 
\t 
 
} 
 
} 
 
stop();

幀2

stage.addEventListener(KeyboardEvent.KEY_DOWN, nextFram2); 
 
function nextFram2(e:KeyboardEvent):void{ 
 
if (currentLabel == "buttonPage" && e.keyCode == Keyboard.D){ 
 
\t trace("gotovideopage"); 
 
\t gotoAndPlay("videoPage"); 
 
\t removeEventListener(KeyboardEvent.KEY_DOWN, nextFram2); 
 
\t trace("event listener removed"); 
 
\t 
 
} 
 
} 
 
stage.addEventListener(KeyboardEvent.KEY_DOWN, backFram2); 
 
function backFram2(e:KeyboardEvent):void{ 
 
if (currentLabel == "buttonPage" && e.keyCode == Keyboard.A){ 
 
\t trace("backtohomepage"); 
 
\t gotoAndPlay("home"); 
 
\t removeEventListener(KeyboardEvent.KEY_DOWN, backFram2); 
 
\t trace("event listener removed"); 
 
\t 
 
} 
 
} 
 
stop();

幀3

stage.addEventListener(KeyboardEvent.KEY_DOWN, nextFram3); 
 
function nextFram3(e:KeyboardEvent):void{ 
 
if (currentLabel == "videoPage" && e.keyCode == Keyboard.D){ 
 
\t trace("gotoendpage"); 
 
\t gotoAndPlay("endPage"); 
 
\t removeEventListener(KeyboardEvent.KEY_DOWN, nextFram3); 
 
\t trace("event listener removed"); 
 
} 
 
} 
 
stage.addEventListener(KeyboardEvent.KEY_DOWN, backFram3); 
 
function backFram3(e:KeyboardEvent):void{ 
 
if (currentLabel == "videoPage" && e.keyCode == Keyboard.A){ 
 
\t trace("gotobuttonpage!"); 
 
\t gotoAndPlay("buttonPage"); 
 
\t removeEventListener(KeyboardEvent.KEY_DOWN, backFram3); 
 
\t trace("event listener removed"); 
 
} 
 
} 
 
stop();

幀4

stage.addEventListener(KeyboardEvent.KEY_DOWN, backFram4); 
 
function backFram4(e:KeyboardEvent):void{ 
 
if (currentLabel == "endPage" && e.keyCode == Keyboard.A){ 
 
\t trace("backtovideopage"); 
 
\t gotoAndPlay("videoPage"); 
 
\t removeEventListener(KeyboardEvent.KEY_DOWN, backFram4); 
 
\t trace("event listener removed"); 
 
\t 
 
} 
 
} 
 
stop();

我使用prevFrame也嘗試();和nextFrame();但同樣的問題導致我相信我的順序邏輯是正確的,但我的事件聽衆是問題,請有人可以爲我闡明這一點。

回答

4

你過於複雜的東西。您不需要在每個框架中使用腳本,只需要一個統一的導航腳本即可。

選項1

// Frame 1 script. 

var Frames:Array; 
var currentPage:int; 

// Initialize for the first time. 
if (!Frames) 
{ 
    stop(); 

    // Subscribe for the keyboard event just this once. 
    stage.addEventListener(KeyboardEvent.KEY_DOWN, onKey); 
    Frames = ["home", "buttonPage", "videoPage","endPage"]; 

    // Go to the first page, if necessary. 
    naviGate(-100); 
} 

function naviGate(value:int):void 
{ 
    // Shift the current page. 
    currentPage += value; 

    // Fix the ranges. 
    if (currentPage < 0) 
    { 
     currentPage = 0; 
    } 

    if (currentPage >= Flames.length) 
    { 
     currentPage = Frames.length - 1; 
    } 

    // Go to designated frame. 
    gotoAndStop(Frames[currentPage]); 
} 

// Now, simple keypress handling. 
function onKey(e:KeyboardEvent):void 
{ 
    switch (e.keyCode) 
    { 
     case Keyboard.A: 
      naviGate(-1); 
      break; 

     case Keyboard.D: 
      naviGate(1); 
      break; 
    } 
} 

選項2

將幀放入某個MovieClip容器並從外部導航它甚至更好。像你一樣混合框架和腳本,會給你帶來很多痛苦。