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

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.

Related

Actionscript 3: How to have a keyboard Keystroke "Button" go to specific Frame FROM a specific Frame?

I'm Super New to Programming in general and very New to Actionscript 3. It's been a rough but fun ride.
Anyway For the work I am doing I have my animation Play up to a certain point and it asks the viewer a question, The viewer has 3 choices, and each of those choices are connected to a button on the keyboard. A B C or D.
After searching for someone with a similar problem, My solution so far is this:
stage.addEventListener(KeyboardEvent.KEY_DOWN, cNote);
function cNote(event:KeyboardEvent):void {
trace(event.keyCode);
if (event.keyCode==67) {
gotoAndPlay(21);
}
I have this repeated 4 times each for the different Keys.
This works and allows me to move the viewer to the Frame with their response, however Any time during the animation they can press the button and it will move them to the Frame of the corresponding button (in this case Frame 21). How do I set it so that the keypress will only respond and move them to Frame 21 when they are on Frame 20 for example? (I suspect it has something to do with the "stage" part in the code but I cant get it to work without it.)
I also have the audio for the animation on a separate Layer and even though the visuals change as it goes to the correct frame, the audio continues as if the key was not pressed. Is there also a way to connect the key to make it stop the current audio and then play the new audio? Or is there a better way to do this?
Sorry if this is confusing. Thank you for your help :)
It has been quite awhile since I touch flash. From what I remembered, you can click on the frame at your movieclip, insert a keyframe by pressing f6, and press f9 to insert the listener at that frame and that frame only, after an input has been pressed, you remove it. for example:
if (event.keyCode==67) {
gotoAndPlay(21);
stage.removeEventListener(KeyboardEvent.KEY_DOWN, cNote);
}
For the audios, I usually plays them using code, but I'm quite sure there's a way to drag and drop the audio from library to the movieclip. so I can do sound1.play(), when a button is pressed, I can do sound1.close() and sound2.play()
For more reference:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Sound.html

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();
});

How to put music in individual scenes and have it change when i select a new scene

Alright I've managed to make an almost web page style thing in flash. I have all the coding to navigate the pages finished, but now I'm having the issue of when I change pages my main page music continues while the other pages music begins. I.,m unsure of how to code this. can anyone help? also I already have click sound effects going for my buttons and they seem to be working fine. Don't know if that helps at all. I'm also using flash cs6 and don't want to go to cc, because the removal of the bone tool.
To stop a sound, you will need to use a SoundChannel object when you tell the sound to play. Then, with the reference to the SoundChannel, you can stop the sound before you exit the section.
// save this reference for later so you can stop the sound when you want..
var mySoundChannel:SoundChannel = mySound.play(); // Get a sound channel.
// Call this later
mySoundChannel.stop();
Without a SoundChannel to control it, the sound object will do its default behavior, which is to play to completion.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/SoundChannel.html

Movieclip in Front of include .flv

I made a .swf Application which goes automatic to the fullscreenmode with the functions
stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
stage.scaleMode = StageScaleMode.NO_SCALE;
So what i wanted to do is to start a .flv video and in front of this .flv include, i want to have a Movieclip, which is in front of the .flv Video.
That doesn't work, in the Fullscreen mode. If i minimize the windwow. The Movieclip goes in front of the flv- included video.
So what i need is, to have something like a z-index function in the fullscreenmode.
Can anybody help me
Thanks
Flash Player: 11.4
Assuming you have a reference to every Display Object, you could use swapChildren to swap the depth or the z index:
var index1=this.getChildIndex(child1);
var index2=this.getChildIndex(child2);
this.swapChildren(index1,index2)
where child1 & child2 could be any display object including video player.
I'm not in front of Flash right now so I can't test the problem but I'm sure its considered bad practice to have an app that goes auto-fullscreen by itself on loading. Adobe considered it a security risk and they may have taken security steps that conflict with what you're doing... just a guess though.
"That doesn't work, in the Fullscreen mode. If i minimize the windwow.
The Movieclip goes in front of the flv- included video."
My advice is to make a button somewhere on the screen for going in/out of fullscreen. So when it looks okay in the window mode, click that button to go fullscreen again and then tell me if its okay now or is the problem still happening?
A) If its okay then you need to lose auto-fullscreen and just start with a button on stage. Give it text label like "Start App" or something like that so users know what to do (much better than just throwing them in fullscreen with some unexpected loud video etc).. Anyway when in fullscreen thats when your function should addChild the flv container MC and then your other MC. Use removeChild commands when F.S mode is exited. Make the "Start" button visible or hidden depending on screen mode (F.S is hidden, Window is visible etc).
B) If its not okay you have other problems.. I'm off to sleep but will check later if there's a reply. Peace..
I made my own solution :
var container:Sprite = new Sprite();
container.addChild(logo);
container.addChild(startVideo);
container.swapChildren(logo, startVideo);
this.addChild(container);
Whith this Sprite object it works fine.

Flash video player scrubber dragging past progress bar fill

I'm trying to troubleshoot the scrubber for a custom video player and I'm coming across an issue with the scrubber being dragged past the progress bar fill if the flv hasn't fully loaded.
The player is here:
http://mindfilemultimedia.com/stage/portfolio.html
If you play the video you will see that while the flv is still downloading, when you move the scrubber past the yellow progress bar into the white part of the line, the video player will freeze. It is doing that because the user is telling it to seek to a part of the video that has not been fully downloaded yet. What I want it to do is determine if the flv is still downloading and restrict the user to only be able to drag the scrubber up until the width of the yellow progress bar. Right now I have set the code to retrieve the bytesLoaded and bytesTotal and what I want to do is to say something like (in actionscript 3):
if (videoPlayer.bytesLoaded < videoPlayer.bytesTotal) {
var newBounds:Rectangle = new Rectangle(0, 0, (videoPlayer.bytesLoaded/videoPlayer.bytesTotal) * MovieClip(root).SeekBar.SeekProgressBar.width, 0);
MovieClip(root).SeekBar.SeekBarHandle.startDrag(false, newBounds);
}
I am by no means an actionscript person, so that was my attempt at doing what I needed. I have a feeling that it is not working because I'm accessing the classes incorrectly for the progress bar and the scrubber handle, but I am just taking the default classes as the seekbar was a flash components. Well, I can just be completely wrong. Any help here would be appreciated.
Where are you putting this code? It needs to be put somewhere, where it is updated regularly. Depending on what type of video player you were using you could see what events it dispatches and use an event listener to regularly check how much has been buffered. You could also use the enter frame event although you would need to make sure you stopped listening once the buffer is complete as it would add extra overhead on every frame.
As a side note SeekBar and SeekBarHandle should probably be seekBar and seekBarHandle respectively, as it's standard practice to start instance names with a lowercase letter in actionscript.