How can I stop one SWF file playing when playing another in a HTML page?
I currently have a carousel that displays multiple SWF files and I don’t want any overlapping of video or audio. I’ve been looking into LocalConnection and JavaScript options but with no luck.
My SWF files are currently ActionScript 3 and Flash Player 10.
I have a large play button on them, with the ActionScript code:
import fl.video.VideoEvent;
import fl.video.VideoState;
video.addEventListener(VideoEvent.STATE_CHANGE,showButton);
playVideoButton.addEventListener(MouseEvent.MOUSE_UP,playVideo);
function playVideo(event:MouseEvent):void {
video.play();
playVideoButton.visible=false;
}
function showButton(event:VideoEvent):void {
switch (event.target.state) {
case "stopped" :
playVideoButton.visible=true;
break;
case "playing" :
playVideoButton.visible=false;
break;
case "paused" :
playVideoButton.visible=true;
break;
}
}
Is there a way to incoporate a “stop the other SWF files playing” in this somehow?
What you’ll want to do is set up an
ExternalInterfacecallback method in each SWF file. That will allow JavaScript to call a function within your SWF file.So for instance, you could set up a function called
stopPlaying()and that’s that.Then, you set up a JavaScript function called
playVideo(string:String)that callsstopPlaying()on every SWF file except the one that is associated with the string that you pass in.Whenever someone hits play in one of your SWF files, do
ExternalInterface.call("playVideo", "myString")and your JavaScript function should work.