我在带有 watch 按钮的电影中有4个帧中的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
}
答案 0 :(得分:1)
就在gotoAndStop()函数之前,只需放入movie1_mc.stop();命令,这将在更改帧之前停止剪辑。
只是在发展方面,如果你只是改变视频,只考虑使用一帧,并使用addChild()和removeChild()从舞台添加/删除视频。事情往往更容易控制整体绕过像这样的框架,是一个很好的学习工具。
答案 1 :(得分: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帧停止(原始代码中未包含))... I如果你想使用它们,可以添加它。
但是在帧之间有更简单的方法。 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文件更小。它也有自己的电影控制,所以暂停,停止,播放和其他都立即可用,没有必要的听众事件。
玩得开心,实验!
我希望这有帮助!