2012-11-27 17 views
0

我有5個圖層,每個圖層上都有符號:a,b,c,d和e。 我試圖解決如何將行動波紋管應用於a,c,d和e時,當您將鼠標懸停在b上時。如何將動作應用於多個閃存圖層

還有另一種類似'gotoAndStop(0)的動作; '而不是立即進入第0幀,它回到了它的方式?

鏈接.FLA http://www.fileden.com/files/2012/11/27/3370853/Untitled-2.fla

stop(); 

stage.addEventListener(MouseEvent.MOUSE_OVER, playMovie); function playMovie(event) { play(); } 
stage.addEventListener(MouseEvent.MOUSE_OUT, stopMovie); function stopMovie(event) { gotoAndStop(0); } 


stop(); 

感謝

+1

小側面說明:您gotoAndStop使用0,但基於幀不爲零,它開始於第1幀 –

+0

@MarkKnol - 漂亮的抓 – BadFeelingAboutThis

+0

順便說一下它不給任何錯誤,如果默認爲1. –

回答

1

編輯

看着你的根後,這裏是缺少/放錯了地方:

  1. flash中的圖層並不意味着任何o而不是z-階/深度。你不能在代碼中操作圖層。你所有的動畫都在同一時間線上,所以他們會一直玩。如果你想讓一個單獨的項目在沒有其他項目的情況下進行動畫製作,那麼你必須在它自己的時間線上進行動畫製作(而不僅僅是圖層)。雙擊它即可訪問符號自己的時間軸 - 在那裏做動畫。

  2. 要引用舞臺上的項目,您需要給它們一個實例名稱。您可以通過單擊舞臺上的項目來完成此操作,然後在屬性面板中可以放置實例名稱的字段。對於下面的代碼工作,你需要分別給他們一個實例名稱「a」,「b」,「c」,「d」,「e」。這與庫中的符號名稱不同(儘管它可以是相同的名稱)。你可以這樣做


方式一:

var btns:Vector.<MovieClip> = new Vector.<MovieClip>(); //create an array of all your buttons 
btns.push(a,b,c,d,e); //add your buttons to the array 

for each(var btn:MovieClip in btns){ 
    btn.addEventListener(MouseEvent.MOUSE_OVER, btnMouseOver); // listen for mouse over on each of the buttons 
    btn.addEventListener(MouseEvent.MOUSE_OUT, btnMouseOut); 
} 

function btnMouseOver(e:Event):void { 
    for each(var btn:MovieClip in btns){ //loop through all your buttons 
     if(btn != e.currentTarget){ //if the current one in the loop isn't the one that was clicked 
      btn.play(); 

      try{ 
       btn.removeEventListener(Event.ENTER_FRAME,moveBackwards); //this will stop the backwards animation if running. it's in a try block because it will error if not running 
      }catch(err:Error){}; 
     } 
    } 
} 

function btnMouseOut(e:Event):void { 
    for each(var btn:MovieClip in btns){ //loop through all your buttons 
     if(btn != e.currentTarget){ //if the current one in the loop isn't the one that was clicked 
      goBackwards(btn); 
     } 
    } 
} 

有向後播放時間軸沒有很好的方式,但也有辦法做到這一點。一種這樣的方式:

//a function you can call and pass in the item/timeline you want played backwards 
function goBackwards(item:MovieClip):void { 
    item.stop(); //make sure the item isn't playing before starting frame handler below 
    item.addEventListener(Event.ENTER_FRAME, moveBackwards); //add a frame handler that will run the moveBackwards function once every frame 
} 

//this function will move something one frame back everytime it's called 
function moveBackwards(e:Event):void { 
    var m:MovieClip = e.currentTarget as MovieClip; //get the movie clip that fired the event 
    if(m.currentFrame > 1){ //check to see if it's already back to the start 
     m.prevFrame(); //if not move it one frame back 
    }else{ 
     m.removeEventListener(Event.ENTER_FRAME,moveBackwards); //if it is (at the start), remove the enter frame listener so this function doesn't run anymore 
    } 
} 
+0

我收到一個錯誤,說他們是未定義的屬性?我也不認爲我說得很清楚,但是我希望這會發生在每個字母(a b c d和e [不僅僅是b]) 謝謝 – maxmitch

+0

它表示「期待分號前小於」,並且這是放在同一時間軸上。謝謝 – maxmitch

+0

你的5個符號需要有實例名稱,所以你可以通過代碼引用它們。在點擊舞臺上的一個後,您可以在屬性面板中執行此操作。 – BadFeelingAboutThis

相關問題