I've been searching for an answer to this one for a few days. No one seems to know a definitive solution, just a lot of half-guesses dating back through several years of forum discussions and several versions of ActionScript.
Basically, on the same frame of my main timeline I have a MovieClip containing my navigation buttons, and a MovieClip containing site content -- on Frame 1 resides the synopsis of a film, and on Frame 2 resides the film trailer. I am using Flash CS4's FLVPlayback component as my media player, and it loads my external FLV video file dynamically.
Here's the hierarchy:
MAIN TIMELINE- Navigation Bar (MovieClip)
Button 1
Button 2
- Content Pages (MovieClip)
Frame 1: Synopsis (Text & Graphics)
Frame 2: Trailer (FLVPlayback Component)
External FLV File
And the ActionScript 3.0 code on the first frame of the Navigation Bar MovieClip is as follows:
PHP Code:
btn1.addEventListener(MouseEvent.CLICK, btn1Click);
btn2.addEventListener(MouseEvent.CLICK, btn2Click);
function btn1Click(event:MouseEvent):void {
MovieClip(parent).contentPages.gotoAndPlay("synopsis");
}
function btn2Click(event:MouseEvent):void {
MovieClip(parent).contentPages.gotoAndPlay("trailer");
}
When you press Button 1, it plays the Content Pages MovieClip and takes you to the frame labeled "synopsis," and you can read the synopsis.
When you press Button 2, it also plays the Content Pages MovieClip and takes you to the frame labeled "trailer," where the FLVPlayback Component starts playing the film trailer FLV file automatically. That's all fine and dandy.
However, the problem occurs when you try to navigate away from the "trailer" frame. Let's say you press Button 1 again, it takes you back to the "synopsis" frame like it should, but at the same time, the FLVPlayback Component on the "trailer" frame continues playing in the background -- you can still hear the audio of the FLV file playing, even though the video is off the stage and you can't see it anymore.
To make matters even worse, let's say you press Button 2 again. It will take you back to the "trailer" frame and begin playing the FLV file again from the beginning, yet the
first occurrence of the FLV file is still playing in the background, so now there's an "echo" effect from the two layers of audio.
So, my question is, Why does the FLVPlayback Component continue playing even when it is no longer on the stage? And more importantly, what ActionScript 3.0 code can I implement to tell FLVPlayback to stop playback when it is no longer on stage? I tried coding an EXIT_FRAME event above the "trailer" frame so it would stop playing when not on that frame, but that didn't work. I also tried adding this code to the functions of my navigation buttons to try to stop the FLVPlayback when you click a navigation button, with no luck:
PHP Code:
btn1.addEventListener(MouseEvent.CLICK, btn1Click);
function btn1Click(event:MouseEvent):void {
MovieClip(parent).contentPages.gotoAndPlay("synopsis");
MovieClip(parent).contentPages.trailerPlayback.stop();
// "trailerPlayback" is the instance name of my FLVPlayback Component
}
This problem is driving me batty. If anyone has a solution, please send it this way!