Flash CS6 AS3 play sound on one frame only, stop when left frame - actionscript-3

I have a scene which has a frame for each screen that I want to display to the user. Each frame has a movieclip which contains all the elements for that screen. The first frame's movieclip has frame1 set up with a sound layer. Problem is, when I navigate to a different screen, the music continues to play.
How can I get it to only play whilst the movieclip is visible on the screen? I tried to have an "ENTER_FRAME" listener of the other screens and used SoundMixer.stopAll(); which stopped the music. The only problem is, when I reentered the frame with music, it wouldn't start.
I am using the Sync Setting: Stream.

Flash IDE has a number of different kinds of sounds, the most important being Stream and Event.
It sounds like you're using an Event type sound because the sound continues to play even when you are off the frame. There is no way to stop an Event sound except with SoundMixer.stopAll().
You need to set the sound type to Stream in Flash IDE. Then, place it in a MovieClip and make sure that there enough frames in the clip to last the whole duration of the sound. Then, place that MovieClip in your main scene and it should now stop when you move to a different frame.

Related

Play continuous sound no matter where you are on the timeline

Is it possible in flash to keep playing the same sound even if I jump to new frames on the timeline but the sound doesn't jump.
So have your sound file in the first frame, select the frame with the sound in it and look at the properties tab, there is a drop-down window that says sound, inside is a sync option, set it to start and loop. That seems to make it play indefinitely.
you can do it grammatically
check this out
https://stackoverflow.com/a/5443790/3623547

Flash Actionscript 3.0 MovieClip Transitions (No Buttons)

I have 3 mc_MovieClips.
Each clip is on a different frame of the same layer in the main scene.
I do not want to use a button to control the play.
On startup, I want Clip1(On Frame1) to play, and when that is finished, Clip2(On Frame2) will play and so on.
I am a very beginner and using Flash Professional CC and actionscript 3.0. The only help I can seem to find calls for global variables, which no longer seem to exist.
I can provide more information if needed, I am just a really big beginner.
Try placing a parent.nextFrame(); on the last frame of each MovieClip and a stop(); on each frame of the parent clip (actual frames of your main scene).

Need to create a pause/resume toggle button in Flash CS3 AS3

OK, I have seen a lot of questions and answers on how to code pause/resume buttons, but none of them fit my specific need. First let me explain what I have:
I have made a tutorial video for my job. It consists of screens shots and sounds. I have a forward button that skips to the next section (usually the start of the next audio file) and a back button that goes to the previous section. However I need a pause button.
Now let me explain how I have built it:
I have made the movie at 1fps. I have a layer for Audio, a layer for the screen shots, a layer for each button, and various other layers for highlighting things in the screen shots. On the Audio layer I placed my audio file on the stage and then dragged out the number of frames until the entire audio file could play uninterrupted. So if the audio was 10 seconds long, it lives across 10 frames. I can then put my screenshot on its own layer and do the same so that the image displays the same length of time as the audio. When the frame ends, it automatically skips to the next frame and continues on until the end. Since the audio is on the stage, the viewer doesn't need to do anything to get the audio to play.
After viewing many tutorials, it seems like most people use code to get the audio to play rather than putting it on the stage. I am not this skilled.
So my question is, with my current set up, how can I make a toggle button that basically says "If audio is playing, stop the whole show when clicked- if audio is not playing, resume show from last position when clicked"?
Thank you so much if you can help! Also, this is my first time asking a technical question like this, please let me know if you need any other specific details.
First make sure all audios on your timeline are set to "Stream". To
do this click on the frame where your audio lies, find the sound
panel, change it from Event to Stream. this will ensure that when
the timeline is stopped the audio stops and resumes when the
timeline is played.
As for the buttons simply make one that calls stop() on the timeline and one that calls play(). This will stop the timeline wherever it is and resume it on play.
var myTimeline:MovieClip;//link to the movieclip where your timeline animation lies
var btnPause:SimpleButton;//link to your pause button
btnPause.addEventListener(MouseEvent.CLICK,function(event:MouseEvent):void{
myTimeline.stop();
});
var btnResume:SimpleButton;//link to your resume button
btnResume.addEventListener(MouseEvent.CLICK,function(event:MouseEvent):void{
myTimeline.play();
});

Disabling Audio Flash

When creating an AS3 project and adding audio what I usually do is drag the audio I want to use (for a game menu for example) and when I want to stop the audio I enter
SoundMixer.stopAll();
I do this because if I say go to the about game frame in this menu then I will have the audio, but if I come back to the main frame where I originally had the music it sorta doubles in and the two different timings of the music are playing at the same time.How do I stop this without having to disable the audio when I change frame?
In these cases, it is easier to start and stop the sound directly via code. First, right click the sound clip in your Library panel, and select Properties. In the ActionScript tab, check "Export for ActionScript", and give it a class name of, say, Music. Then, to play and stop this clip, you can use this code:
import flash.media.Sound;
// create the music Sound object so that we can start playing
var music : Sound = new Music();
var musicChannel : SoundChannel;
// play the music
// the play() method returns a SoundChannel,
// which you can later use to stop the music
// notice that we first check to make sure musicChannel is null
// if it isn't null, music is already playing, so don't play it twice
if(musicChannel != null) musicChannel = music.play();
// when you switch screens, stop the music
// clear out the channel, so that we know that it is safe to start the music again
musicChannel.stop();
musicChannel = null;
Alternatively, if you play music and sounds by placing them on the timeline, you can stop it by using the Sync setting of the frame. On the timeline, create a keyframe where you switch screens and want the music to stop playing. Select that frame, and drag the sound clip you want to stop onto that frame. In the Properties panel, change the Sync option to Stop. This will cause only the selected sound to stop playing.
Yet another method is to create an empty MovieClip with the sound placed inside of it. Change the Sync setting to Stream, and pad the clip out with empty frames so that it will play the entire clip. Then, if you place this clip on your main menu screen, then it will only play during the main menu. Stream sounds only play the sound for as long as the MovieClip exists and is playing. Compare this to normal Event sounds, which will play the entire sound regardless.
The latter methods are more old-school and movie-centric. If you are programming a game, it would be more appropriate to use the former method to give you more control of the audio in code.

How to ENTIRELY remove an flvplayback from stage when going to another flvplayback on another frame?

I'm trying to create an EXE projector using flash 5.5 AS3 where I have a few videos (FLVs) to show (their location is right next to the exe file in the same directory) - each load in a different frame, and all of those videos should also have a full screen option to them. Those are original videos that people WILL want to watch in full screen. It's essential for the experience...
The problem(s) I currently have (after fixing the sound that didn't stop after going to a different video) are hard to describe, but I'll try really hard.
Ok, so when I click the full screen button on a video and watch it in full screen, I will eventually want to exit the full screen, so I click on the same icon at the bottom to exit full screen (or ESC button, it's the same) and then click the navigation button to go to the SECOND FLV's frame to watch the other video. After watching the second video in full screen and then exiting full screen, flash takes me to the FIRST video's frame and that is a big problem. Also, now the button that takes me BACK to the second video's frame won't work. It's like flash is stuck.
I use the Components --> FLVPlayback 2.5 from the componant menu (I don't really know AS3 programming) and I fix its properties in the component parameters.
Also, I don't think that any of the followings are the reason for the bug, but I use these 3 scripts to stop all sound when navigating away from one frame (with an FLVplayback) to
another frame with another FLVplayback:
MyFLV.stop();
SoundMixer.stopAll();
MyFLV.addEventListener(Event.REMOVED_FROM_STAGE,xyz);
function xyz(e:Event):void{
MyFLV.stop();
}
I've found these online where people asked help for the sound bug I described.
The third script was suppose to remove the FLVplayback from the stage before going to another frame, but it works only when NOT GETTING INTO FULL SCREEN. I need something that will COMPLETELY remove the previous video from the stage so after exiting the SECOND viewed video, flash won't take me to a video that from some reason is still in its memory. I have something like 30 videos in my project and I need to remove each and every one of them off of the stage before navigating to the next frame to open a new FLVPlayback.
I tried to add a link to a demo I made with the problem so you can look at it, but it triggered a "oops, something went wrong" error, probably anti spam mechanism...
I would recommend using only one frame and only one flvplayback instance. Otherwise you have to deal with weird bugs like the one you are getting (usually caused by misplaced or forgotten code). Of course, using only one frame requires using more code, but with the number of hard-fixes it looks like you were making for the bugs, you may end up with less code.
Don't worry, I'll walk you through everything!
Reasons to use code (as opposed to multiple frames):
Easier to keep track of:
Know where all your code is so you can easily find and fix any problems.
Make changes more easily
You want to switch an existing video? edit a file reference and you are done.
Want to add a video? no more dragging a new flvplayback instance onto a new frame just add some very simple code and a button and you're done.
More customization
Reasons to use multiple frames (and multiple flvplayback instances):
easier to place visually
Some people find it easier when they have an actual movieclip that they can visually place on the stage
Less code
Here we go:
//import flv library
import fl.video.*;
This allows you to use ActionScript to manipulate the flv player
//video playback code-----------------------//
var myVideo:FLVPlayback = new FLVPlayback();
this creates an instance of FLVPlayback called myVideo (referenced from now on in the code as myVideo)
this next chunk shows many of the customizable features of the flv player. It is not necessary to include them.
//places the video player on stage at x,y
myVideo.x = 115;
myVideo.y = -10;
//uses SkinOverPlayFullscreen.swf for controls
myVideo.skin = "SkinOverPlayFullscreen.swf";
//color of controls
myVideo.skinBackgroundColor = 0x333333;
//hide controls and time it takes controls to fade and reappear (milliseconds)
myVideo.skinAutoHide=true;
myVideo.skinFadeTime=300;
//add the player to the stage
addChild(myVideo);
And now comes the important part. I have made buttons and added them to the stage. I gave each of the buttons a different instance name (box1_btn, box2_btn, and box3_btn). When someone clicks on a button, an "event" will occur.
//button listener code-------------------------//
//when button 1 is clicked throw button 1 event
box1_btn.addEventListener(MouseEvent.CLICK, clicked1);
//when button 2 is clicked throw button 2 event
box2_btn.addEventListener(MouseEvent.CLICK, clicked2);
//when button 3 is clicked throw button 3 event
box3_btn.addEventListener(MouseEvent.CLICK, clicked3);
//play different videos for different buttons---------//
//when button 1 event is thrown
function clicked1($e:MouseEvent):void
{
//play video 1.flv
myVideo.source = "1.flv";
}
//when button 2 event is thrown
function clicked2($e:MouseEvent):void
{
//play video 2.flv
myVideo.source = "2.flv";
}
//when button 3 event is thrown
function clicked3($e:MouseEvent):void
{
//play video 3.flv
myVideo.source = "3.flv";
}
This code will not have any sounds that keep playing because two videos cannot play at the same time in one instance of the player. Nor will it have any mess-ups when you come out of fullscreen because there is only one frame for the video to go back to.
Some possible problems you may run into:
It doesn't work at all:
Make sure you have added an instance of FLVPlayback to the library by adding an instance to the stage from the components menu (window>>components or ctrl+F7) and then deleting it from the stage (it should still appear in the library).
The playback buttons I want aren't showing up:
There is a great explanation of how to use As3 to manipulate FLVPlayback here:
http://www.republicofcode.com/tutorials/flash/as3flvplayback/
find the section about "Applying a Skin to the FLVPlayback Component" and follow it to use an adobe playback skin. If you want to make your own unique skin I would recommend opening and editing one of the pre-made skins. I found mine in
C:\Program Files (x86)\Adobe\Adobe Flash CS6\Common\Configuration\FLVPlayback Skins\FLA\ActionScript 3.0
I hope this helps!
Below would be simplest way to unload the FLVPlayback
removeChild(MyFLV);
it works fine for me
flvPlayBack.stop();
removeChild(flvPlayBack);
stops the sound and removes the playback.