2013-09-27 100 views
0

基本上我試圖創建兩個按鈕。他們都在用戶將光標放在它們上時(而不是onClick或類似的東西)調用動作。按住按鈕時播放時間線

第一個播放時間線,這很好。

第二個我需要它在用戶按住按鈕時反向播放時間線,我該怎麼做?下面的代碼:

import flash.events.MouseEvent; 


// Play timeline forwards on click // 
function onButtonClick(event:MouseEvent):void 
    { 
     play(); 
    } 
RotateRight.addEventListener(MouseEvent.MOUSE_DOWN, onButtonClick); 

// Stop timeline forwards on release // 
function onButtonClick2(event:MouseEvent):void 
    { 
     stop(); 
    } 
RotateRight.addEventListener(MouseEvent.MOUSE_UP, onButtonClick2); 



// Play timeline in reverse on click // 
function onButtonClick3(event:MouseEvent):void 
    { 
     // PLAY IN REVERSE? 
    } 


RotateLeft.addEventListener(MouseEvent.MOUSE_DOWN, onButtonClick3); 

// Stop timeline in reverse on release // 
function onButtonClick4(event:MouseEvent):void 
    { 
     stop(); 
    } 
RotateLeft.addEventListener(MouseEvent.MOUSE_UP, onButtonClick4); 

任何幫助最讚賞:)

回答

1

您應該MOUSE_DOWN添加ENTER_FRAME事件:

RotateLeft.addEventListener(MouseEvent.MOUSE_DOWN, onButtonClick3); 

function onButtonClick3(event:MouseEvent):void 
{ 
    stop(); 
    stage.addEventListener(Event.ENTER_FRAME, reverse); 
} 

function reverse(e:Event):void { 
    //currently, this is reversing the main timeline. Can also do it to a specific movieclip with something like myMovieClip.gotoAndStop(myMovieClip.currentFrame-1) instead. 
    gotoAndStop(currentFrame - 1); 
} 


RotateLeft.addEventListener(MouseEvent.MOUSE_UP, onButtonClick4); 

// Stop timeline in reverse on release // 
function onButtonClick4(event:MouseEvent):void 
    {  
     stage.removeEventListener(Event.ENTER_FRAME, reverse); 
     //You don't need stop() here, but you can change it to play() if you want to resume playback when the mouse is released. 
    } 
+0

這工作!非常感謝 :) –