Stop the video in flash - actionscript-3

I imported the flv video into movieclip.
How can i stop the video by clicking in work area?
The viewer should be able to pause the video not only by clicking onto the status bar.

You mean the video is in the movieclip, with a movieclip timeline as long as the video ?
If so you could do :
import flash.events.MouseEvent;
var isPaused:Boolean = false;
mc.addEventListener(MouseEvent.CLICK, onClick);
function onClick(evt:MouseEvent){
if (isPaused){
mc.stop();
}else{
mc.play();
}
isPaused = !isPaused;
}

Related

Adobe Flash/ActionScript 3.0 moving to next scene but nothing plays

I've searched endlessly for an answer but can't seem to find one.
I'm building a flash presentation for a client. It's got about 15 scenes, the .fla file is 200MB before publishing (26MB afterward). It's a pretty simple operation; I'have a pause/play & replay button, and once the scene is completed a next & replay button appears in the center of the stage.
My issue is when I get to about the 8th scene, halfway through. All my tweens and buttons stop working. Simple fade-in text doesn't come up and my pause/play & replay no longer function. I've tried shifting around scenes to see if it was anything in particular, but no matter what order and what scenes it always stops halfway through the 8th. I don't get any error notifications before, after or during the play. Tracing tells me that the button has been clicked and it's moved to the next scene but it simply will not play. Adding a play(); comment at the first frame of the next scene has not helped either.
Here are my functions that are on Scene 1 Frame 1
function pause_movie(event:MouseEvent):void {
stop();
playBtn.visible = true;
pauseBtn.visible = false;
}
function play_movie(event:MouseEvent):void {
play();
playBtn.visible = false;
pauseBtn.visible = true;
}
function replay_movie(event:MouseEvent):void {
gotoAndPlay(1);
}
function next_movie(event:MouseEvent):void {
this.nextScene();
trace("next_movie " + this.currentScene.name);
}
And then I just add event listeners when my buttons appear per scene
import flash.events.MouseEvent;
//Hide play button to start
playBtn.enabled = true;
pauseBtn.enabled = true;
playBtn.visible = false;
pauseBtn.addEventListener(MouseEvent.CLICK, pause_movie);
playBtn.addEventListener(MouseEvent.CLICK, play_movie);
replayBtn.addEventListener(MouseEvent.CLICK, replay_movie);
Any help is appreciated! Thank you!
I've created a new flash file with a blank canvas (just page number and next button). I'm loading the audio externally now as per #VC.One 's comment and the program stops working at the same scene regardless of which audio file I put in there.
Here is my updated code:
import flash.events.Event;
import flash.media.Sound;
import flash.net.URLRequest;
import flash.media.SoundChannel;
var channel:SoundChannel = new SoundChannel;
var s:Sound = new Sound();
function newSound() {
s.removeEventListener(Event.COMPLETE, onSoundLoaded);
s = new Sound();
s.addEventListener(Event.COMPLETE, onSoundLoaded);
}
function onSoundLoaded(e:Event):void
{
channel = s.play();
}
function next_movie(event:MouseEvent):void
{
channel.stop();
try {
s.close();
}
catch(e:Error) {
trace("File already loaded");
}
this.nextScene();
trace("next_movie " + this.currentScene.name);
}
and each scene starts with:
pageNum.text = this.currentScene.name;
skipBtn.addEventListener(MouseEvent.CLICK, next_movie);
newSound();
s.load(new URLRequest('audio/ISB page 17 tk 1.mp3'));
Finally solved this issue. The scenes added together were more than the 16k frames Flash is apparently limited to. I had to convert each scene into a movieclip and put them in each of their own frame all in one scene with a bit of coding to play each one after the previous one finished. Everything works fine now. Thanks guys!

Why the background sound keep repeating?

I have one background sound to use in my project. But when I click the button to other scene, the sound repeats themselves and worse, it redundant with the sound in next scene. I was trying to use one background song for the whole project but this problem happened. Can teach me how?
I am using Adobe Flash CS6. Thank you.
the sound is repeating itself because timeline is repeating by default and you should add command stop() in actionscript. You did not provide any source code so I'll assume you don't have any, in your case here is a sample program in actionscript that loops the background music.
import flash.events.MouseEvent;
stop(); //<-- make sure to stop timeline
var bgMusic:Sound = new BGMusic();
var bgChannel:SoundChannel = new SoundChannel();
bgChannel = bgMusic.play();
bgChannel.addEventListener(Event.SOUND_COMPLETE, loop);
startButton.addEventListener(MouseEvent.CLICK, startGame);
function startGame(e:MouseEvent):void {
gotoAndStop(1, "Scene 2"); //<-- stop after clicking button
}
function loop(e:Event):void {
bgChannel = bgMusic.play();
bgChannel.addEventListener(Event.SOUND_COMPLETE, loop);
}

Loop youtube clip on flash As3

I have this code which playing youtube movie in flash As3.
it working fine, but i can't make that movie will play again on ending.
any ideas?
here the code:
Security.allowDomain("www.youtube.com");
var my_player:Object;
var my_loader:Loader = new Loader();
my_loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3&loop=1;"));
my_loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
function onLoaderInit(e:Event):void{
addChild(my_loader);
my_player = my_loader.content;
my_player.addEventListener("onReady", onPlayerReady);
}
function onPlayerReady(e:Event):void{
my_player.setSize(300,300);
my_player.loadVideoById("indux8D-SoA&loop=1;",0);
my_player.mute();
}
thanks a lot!
You should use "onStateChange" event listener for your my_player object.
And check when it pass 0 or YT.PlayerState.ENDED.
my_player.addEventListener("onStateChange", onPlayerStateChange);
function onPlayerStateChange(event:Event):void {
if(Object(event).data==0){
//reload, restart, rewind and so on code here;
}
}
Alternatively you could load youtube playlist with one video using getPlaylist()and use
setLoop method to loop playback of this "list"
my_player.setLoop(true);

Flash Youtube Embed Issue

Ive embedded a youtube video into a flash file with different frames for different pages, basically when i click off the page displaying my video, the youtube video is still on screen and the sound carrys on playing. I want the video only to be displayed on one frame, and the sound to stop when i switched frames. Here is my code:
Security.allowDomain("www.youtube.com");
var player : Object;
var mute : Boolean = false;
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3"));
playButton.addEventListener(MouseEvent.CLICK, playVideo);
pauseButton.addEventListener(MouseEvent.CLICK, pauseVideo);
muteButton.addEventListener(MouseEvent.CLICK, muteVideo);
function onLoaderInit(event:Event):void {
addChild(loader);
loader.content.addEventListener("onReady", onPlayerReady);
}
function onPlayerReady(event:Event):void {
player = loader.content;
player.setSize(520, 265);
player.x = 230;
player.y = 370;
player.cueVideoByUrl("http://www.youtube.com/v/G-P9fO4g2Jc", 0);
}
function playVideo(event:MouseEvent):void {
player.playVideo();
}
function pauseVideo(event:MouseEvent):void {
player.pauseVideo();
}
function muteVideo(event:MouseEvent):void {
if(!mute){
player.mute();
mute = true;
return;
}
else {
player.unMute();
mute = false;
}
}
Thanks in advance
The addChild method adds child to the hole movieClip rather than to the currentFrame, actually there isn't way to add child to the give frame.
Possible solutions are:
Create empty sprite in the frame where you need to insert the player and use this sprite as the holder. Don't forget to stop the video when you leave the frame (you can listen the Event.REMOVED_FROM_STAGE event of player for example and stop video in handler).
add onEnterFrame event listener and check the currentFrame property, when it's the target frame add video otherwise remove video.

Stopping the sound of a child swf

The timeline of my child swf, there are layers with specific sound files in them to be in sync with my animation. Now the problem arises when I try to import this swf into my main flash website using a loader and the sound will continuously play everytime the button is clicked in the parent. My question is how do I get the sound to completely clear itself and restart from frame 0 of the child swf upon every click of the button that loads the child into the loader within the parent.
var myLoader:Loader = new Loader();// create a new instance of the Loader class
var project1:URLRequest=new URLRequest("Projects/Q1/Flash_Projects/Greeting_Card/GreetingCard.swf");
var project2:URLRequest=new URLRequest("Projects/Q1/Flash_Projects/Landscape/Landscape.swf");
var project3:URLRequest=new URLRequest("Projects/Q1/Flash_Projects/SpaceInvadersTribute/Main.swf");
var project4:URLRequest=new URLRequest("Projects/Q1/Flash_Projects/RandomImageProducer/RndImgProd.swf");
//var project5:URLRequest = new URLRequest("Projects/Q1/Flash_Projects/Tutorial/Main.swf");
var project6:URLRequest=new URLRequest("Projects/Q1/Flash_Projects/Soundboard/Main.swf");
btnQ1P1.addEventListener(MouseEvent.CLICK,Greeting);
btnQ1P2.addEventListener(MouseEvent.CLICK,landscape);
btnQ1P3.addEventListener(MouseEvent.CLICK, tribute);
btnQ1P4.addEventListener(MouseEvent.CLICK, slideshow);
//btnQ1P5.addEventListener(MouseEvent.CLICK, tutorial);
btnQ1P6.addEventListener(MouseEvent.CLICK, soundboard);
addChild(myLoader);
function Greeting(event:MouseEvent):void {
SoundMixer.stopAll();
myLoader.load(project1);
myLoader.x=550;
myLoader.y=130;
}
//Errors with Sound clips
function landscape(event:MouseEvent):void {
SoundMixer.stopAll();
myLoader.load(project2);
myLoader.x=440;
myLoader.y=130;
}
function tribute(event:MouseEvent):void {
SoundMixer.stopAll();
myLoader.load(project3);
myLoader.x=550;
myLoader.y=170;
}
//Errors with slideshow Code!
function slideshow(event:MouseEvent):void {
SoundMixer.stopAll();
myLoader.load(project4);
myLoader.x=530;
myLoader.y=130;
}
//function tutorial(event:MouseEvent):void{
//SoundMixer.stopAll();
//myLoader.unload();
//myLoader.load(project5);
//myLoader.x = 440;
//myLoader.y = 130;
//}
function soundboard(event:MouseEvent):void {
SoundMixer.stopAll();
myLoader.load(project6);
myLoader.x=550;
myLoader.y=130;
}
I had this same problem.
You need to change the sound from "Event" to "Stream". In Flash Professional, this can be accessed from the properties tab of the sound on the timeline. Click on the sound, and then go to the Properties tab and change the type from Event to Stream.
Now, the sound will stop when the timeline is stopped.