【问题标题】:How can I stop a movie from playing when I click on next frame - FLASH CS4?单击下一帧时如何停止播放电影 - FLASH CS4?
【发布时间】:2010-04-08 19:18:47
【问题描述】:

我在带有 watch 按钮的电影中有 4 帧中的四个电影剪辑 (.f4v)。这些 f4v 已被导入到具有下一个和上一个按钮的主电影容器中。但是,如果我播放电影然后点击下一帧,电影将继续在后台播放。我怎么买这个?下面的代码显示了其中一个影片剪辑的动作脚本,然后是主影片中的动作脚本。我是一个闪光新手,所以所有的帮助表示赞赏。 非常感谢。

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

}

【问题讨论】:

    标签: actionscript-3 flash-cs4


    【解决方案1】:

    就在 gotoAndStop() 函数之前,只需放入一个 movie1_mc.stop();命令,这将在更改帧之前停止剪辑。

    仅在开发方面,如果您只是更改视频,请考虑仅使用一帧并使用 addChild() 和 removeChild() 从舞台添加/删除视频。像这样的框架通常更容易控制整体走动,是一个很好的学习工具。

    【讨论】:

    • 谢谢一百万!我一定会研究 addChild 函数。
    【解决方案2】:

    你有一些很好的逻辑可以在帧之间移动,但是有很多是不必要的。使用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 文件更小。它还拥有自己的电影控件,因此暂停、停止、播放等都可以立即使用,无需监听器事件。

    玩得开心,尝试一下!

    我希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-07
      • 1970-01-01
      • 1970-01-01
      • 2013-08-08
      • 1970-01-01
      • 1970-01-01
      • 2014-10-05
      相关资源
      最近更新 更多