2010-04-08 41 views
1

我有四個電影剪輯(.f4v)在一個電影中的4個幀與手錶按鈕..這些f4vs已被導入到一個主要的電影容器,具有下一個和上一個按鈕。但是,如果我玩電影,然後點擊下一幀,電影繼續在後臺播放。我該如何購物?下面的代碼顯示了其中一個電影剪輯的actionscript,然後顯示了主電影中的actionscript。我是一個Flash新手,所有的幫助表示讚賞。 非常感謝。當我點擊下一幀時,如何停止播放電影 - FLASH CS4?

stop(); 

watch1_btn.addEventListener(MouseEvent.CLICK, playMovie1); 

function playMovie1(event:MouseEvent):void 
{ 
    movie1_mc.play(); 
} 

// Button Listeners 
next_btn.addEventListener(MouseEvent.CLICK, nextSection); 
prev_btn.addEventListener(MouseEvent.CLICK, prevSection); 

function nextSection(event:MouseEvent):void { 

    var thisLabel:String = pages_mc.currentLabel; // gets current frame label as string 
    var thisLabelNum:String = thisLabel.replace("sct", ""); // cuts the leading letters off of the number 
    var curNumber:Number = Number(thisLabelNum); // converts that string number to a real number 
    if (curNumber < 5){ 
     var nextNum:Number = curNumber + 1; // adds 1 to the number so we can go to next frame label 
     pages_mc.gotoAndStop("sct" + nextNum); // This allows us to go to the next frame label 
     } 
} 
/////////////////////////////////////////////////////////////////////////// 
function prevSection(event:MouseEvent):void { 

    var thisLabel:String = pages_mc.currentLabel; // gets current frame label as string 
    var thisLabelNum:String = thisLabel.replace("sct", ""); // cuts the leading letters off of the number 
    var curNumber:Number = Number(thisLabelNum); // converts that string number to a real number 
    var prevNum:Number = curNumber - 1; // subtracts 1 from the number so we can go to next frame label 
    pages_mc.gotoAndStop("sct" + prevNum); // This allows us to go to the previous frame label 

} 

回答

1

就在gotoAndStop()函數之前,放在一個movie1_mc.stop()中;命令,這將在更改幀之前停止剪輯。

只是在事物的發展方面,如果你只是改變視頻考慮只使用一幀,並使用addChild()和removeChild()從舞臺添加/刪除視頻。事情通常是如此容易地控制整體框架,這是一個很好的學習工具。

+0

非常感謝!我一定會看看addChild函數。 – ladygeekgeek 2010-04-14 23:01:38

0

你有一些偉大的邏輯來移動幀,但有很多是不必要的。通過使用currentFrame可以一步獲得當前幀的整數值。這可以幫助清理你的代碼,因爲你不再需要拆分一個字符串然後轉換爲數字。

function nextSection(event:MouseEvent):void { 
// This allows us to go to the currentframe plus one's label in one line of code 
     pages_mc.gotoAndStop("sct" + (pages_mc.currentFrame + 1)); 
} 

function prevSection(event:MouseEvent):void { 
// This allows us to go to the currentframe minus one's label in one line of code 
    pages_mc.gotoAndStop("sct" + (pages_mc.currentFrame - 1)); 
} 

這些功能將移動到前面和後面的框架,但不具備你想要的(如在框架5或第1幀(這是不是在你原來的代碼包括在內)止)功能...如果你想使用它們,我會讓你補充一點。

但是在幀之間還有更簡單的方法。 AS3具有nextFrame()prevFrame()函數,它們完全符合它們的聲音(分別前進到下一幀和前一幀)。

function nextSection(event:MouseEvent):void { 
// This allows us to go to the next frame if we aren't 
// already at frame 5 
    if(pages_mc.currentFrame<5){ 
     pages_mc.nextFrame(); 
    } 
} 

function prevSection(event:MouseEvent):void { 
// This allows us to go to the previous frame if we aren't 
// already at frame 1 
    if(pages_mc.currentFrame>1){ 
     pages_mc.prevFrame(); 
    } 
} 

啊。令人耳目一新。簡單的功能性代碼。


現在,你的實際問題。

mc.stop();(其中mc是實際影片剪輯的佔位符)「停止」影片剪輯。但是「停止」並不是真正在這裏使用的最好的詞。 AS3中的stop()函數更像是一個暫停按鈕,在調用該函數時正在播放的幀中「暫停」該影片剪輯。

當您根據您的代碼返回到任何「已暫停」影片剪輯的幀時,您只能從暫停的位置播放它。

function nextSection(event:MouseEvent):void { 
    if(pages_mc.currentFrame<5){ 

     //"pause" the movie clip (only if moving to another frame) 
     movie1_mc.stop(); 

     pages_mc.nextFrame(); 
    } 
} 

function prevSection(event:MouseEvent):void { 
    if(pages_mc.currentFrame>1){ 

     //"pause" the movie clip (only if moving to another frame) 
     movie1_mc.stop(); 

     pages_mc.prevFrame(); 
    } 
} 

我會推薦使用一些內置的Flash功能來播放.f4v/.flv文件。查看FLVPlayback上的adobe文檔,並查看this answer以查看如何使用它的示例。

FLVPlayback會將文件中的影片剪輯替換爲您的計算機(或服務器)上的文件,從而使您的Flash文件變得更小。它也有自己的電影控制,所以暫停,停止,播放和其他都立即可用,沒有必要的監聽事件。

玩得開心又實驗!

我希望這有助於!

相關問題