当我单击下一帧时如何停止播放电影 - FLASH CS4?

发布于 2024-08-28 04:08:23 字数 1661 浏览 13 评论 0原文

我在带有观看按钮的电影中的 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

}

I have four movie clips (.f4v) in 4 frames in a movie with watch buttons.. These f4vs have been imported into a main movie container that has next and previous buttons. However if i play a movie then hit next frame, the movie continues to play in the background. How can I shop this? The code below shows the actionscript for one of the movie clips and then the actionscript in the main movie. I am a flash newbie, so all help appreciated.
Many thanks.

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

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深爱不及久伴 2024-09-04 04:08:23

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

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

just before the gotoAndStop() function, just put in a movie1_mc.stop(); command, this will stop the clip before changing the frame.

just on a developmental side of things, if you are only changing the video think about using just the one frame and adding/taking away the video from the stage using addChild() and removeChild(). things are usually so much easier to control overall getting around frames like this and is a good tool to learn.

别想她 2024-09-04 04:08:23

您有一些很好的逻辑可以在帧之间移动,但有很多是不必要的。使用 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,并查看 这个答案查看如何使用它的示例。

FLVPlayback 会将文件中的影片剪辑替换为对计算机(或服务器)上文件的引用,从而使 Flash 文件小得多。它还有自己的电影控件,因此暂停、停止、播放和其他操作都可以立即使用,无需侦听器事件。

玩得开心并尝试!

我希望这有帮助!

You have some great logic to move between frames, but there is a lot that is unnecessary. It is possible to get the integer value of the current frame in one step by using currentFrame. This can help clean up your code a bit since you no longer need to split a string and then convert to a number.

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)); 
}

These functions will move to the previous and next frames, but don't have all the functionality you want (such as stopping at frame 5 or frame 1 (which isn't included in your original code))... I'll let you add that if you want to use them.

But there's an even simpler way to go between frames. AS3 has nextFrame() and prevFrame() functions which do exactly what they sound like (advance to the next frame and reverse to the previous frame respectively).

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();
   }
}

Ah. So refreshing. Simple, functional code.


Now, on to your actual question.

mc.stop();, (where mc is a placeholder for your actual movie clip) will "stop" the movie clip. But "stop" isn't really the best word to use here. The stop() function in AS3 works more like a pause button, "pausing" the movie clip at the frame that was playing when the function is called.

When you return to the frame of any "paused" movie clip, based on your code, you will only be able to play it from the point it was paused.

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();
   }
}

I would recommend using some of flash's built in functionality for playing .f4v/.flv files. Check out the adobe docs on FLVPlayback, and check out this answer to see an example of how to use it.

FLVPlayback would replace the movie clips in your file with references to files on your computer (or a server) making your flash file much smaller. It also has its own movie controls, so pausing, stopping, playing, and others are all immediately available no listener events necessary.

Have fun and experiment!

I hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文