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){
开发者_如何学JAVA 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
}
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.
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!
精彩评论