Adobe Flash CS6 - FLVPlayback Start From Time - actionscript-3

I'm working with Adobe Flash CS6 with Action Script 3.0
This is what I have:
This is just a simple explanation of my project. I have 2 pages (frames) in my project: Scene Selection and Watch Video.
On Watch Video, I have a video which play automatically. This video consists of 3 parts: Part 1, Part 2, and Part 3. I also have button Home to go back to Scene Selection.
On Scene Selection, I have 3 images which act as buttons: Part 1, Part 2, and Part 3. If I click button Part 2, I will be directed to Watch Video page, and the video will be skipped to Part 2.
This is the code:
//Scene Selection
btnPart1.addEventListener(MouseEvent.CLICK, OnClickPart1);
function OnClickPart1(event:MouseEvent):void
{
//I think something is missing here
gotoAndStop(3);
}
//Watch Video
import fl.video.FLVPlayback;
import fl.video.VideoPlayer;
import flash.events.Event;
var flvPlayer:FLVPlayback = new FLVPlayback();
var vp:VideoPlayer = flvPlayer.getVideoPlayer(0);
addChild(flvPlayer);
flvPlayer.x = 162.5;
flvPlayer.y = 100;
flvPlayer.width = 1024;
flvPlayer.height = 576;
flvPlayer.source = "Final.mp4";
flvPlayer.skin = "SkinOverPlaySeekMute.swf"
flvPlayer.skinBackgroundColor = 0xF9D760;
btnHome.addEventListener(MouseEvent.CLICK, OnClickHome);
function OnClickHome(event:MouseEvent):void
{
gotoAndStop(1);
CleanFlvPlayer();
}
function CleanFlvPlayer():void{
vp.close();
removeChild(flvPlayer);
}
This is the question:
I don't have problem with Part 1, because it works just like I want. But, how can I skipped the video to a certain time? I can't separate the video into each part, because my real project is more complicated than this. What code should I add? Thanks.

Related

FLASH AS3 Sound Overlap

Alright, I'm a total noob in flash as3 so this must be very easy to solve I guess. I'm making a soundboard with recorded voices in flash cs6, very simple: 1 frame, ten buttons, each button makes a different sound. The problem is the overlapping of these sounds, so what I need is that when I press one button the other sounds stop playing. anyone please?
See the play() method documentation in the Sound class, it returns a SoundChannel object, which has a stop() method.
So you could do it like that (schematically) :
var currentChannel:SoundChannel;
button1.addEventListener(MouseEvent.CLICK, onButtonClick);
button2.addEventListener(MouseEvent.CLICK, onButtonClick);
button3.addEventListener(MouseEvent.CLICK, onButtonClick);
function onButtonClick(event:MouseEvent):void
{
/* provided you have implemented selectSoundByButton func somewhere */
const sound:Sound = selectSoundByButton(event.currentTarget);
if (currentChannel) {
currentChannel.stop();
}
currentChannel = sound.play();
}
More detailed description:
Let's say you want to create yet another fart button application in flash. That's what you have to do:
Create a button symbol, add it to stage and give it an instance name in properties tab. Let's call it myButton
Add the sound to library with file->import
Export this sound to actionscript. Right click on a sound in library, check "Export for actionscript", "export in frame 1" on "actionscript tab". Fill "Class" input with a desired class name for a sound (e.g. MySound)
Then you have to trigger the sound playback on your button click. So you should put the following code to the first frame of your flash clip:
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.MouseEvent;
var currentChannel:SoundChannel;
const mySound:Sound = new MySound();
function onClick(e:MouseEvent):void {
if (currentChannel) {
currentChannel.stop();
}
currentChannel = mySound.play();
}
myButton.addEventListener(MouseEvent.CLICK, onClick);
Add this to your code on each button before playing a sound:
SoundMixer.stopAll();
If you're adding actions directly from the timeline in Adobe Flash, there's no need to import the class. If you're working from an IDE like FlashDevelop or FlashBuilder, add this code to the beginning (after Package {):
import flash.media.SoundMixer;
Happy coding!
Edit: More info on the SoundMixer class

FLVPlayback Event.Complete not detecting video ending

I'm using Flash CC 2015 and Action Script 3.0. The general idea is a menu (that's on frame 1), with buttons that lead to frames with different FLVPlayback components that play videos. Upon completion of the video I want to return to the menu on frame 1.
Here's what I have an frame 2 (where the component is) so far:
import fl.video.*;
stop();
var hole1:FLVPlayback = new FLVPlayback();
hole1.source = "Hole 1.mp4"
hole1.width = 1920;
hole1.height= 1200;
hole1.scaleMode = VideoScaleMode.MAINTAIN_ASPECT_RATIO;
addChild(hole1);
hole1Vid.addEventListener(Event.COMPLETE, playbackComplete);
function playbackComplete(event:Event):void
{
trace("Video End");
gotoAndPlay(1);
}
The main menu links to this frame and plays without any issue, however nothing happens when the video ends.
Thanks in advance for the help!

AS3 Setup Buttons for All Frames in Document Class

I'm making a simple interface with Flash. Let's say we've got:
frame 1: 1 button that advances to frame 10 (goto10)
frame 10: 2 buttons, one advances to frame 20 (goto20), one opens a URL (openURL)
frame 20: 3 buttons, one goes back to frame 1 (goto1), one goes to frame 10 (goto10), and one opens a URL (openURL)
package {
import flash.display.MovieClip
import flash.events.Event;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.display.SimpleButton;
public class NKE_DocumentClass extends MovieClip {
public var goto1:SimpleButton = new SimpleButton();
public var goto10:SimpleButton = new SimpleButton();
public var goto20:SimpleButton = new SimpleButton();
public var openURL:SimpleButton = new SimpleButton();
public function NKE_DocumentClass() {
goto1.addEventListener(MouseEvent.CLICK,function(self:MouseEvent):void{clickGo(self,1)});
goto10.addEventListener(MouseEvent.CLICK,function(self:MouseEvent):void{clickGo(self,10)});
goto20.addEventListener(MouseEvent.CLICK,function(self:MouseEvent):void{clickGo(self,20)});
openURL.addEventListener(MouseEvent.CLICK,function(self:MouseEvent):void{urlGo(self,"http://google.com")});
}
public function clickGo(event:MouseEvent, nextCue:int):void {
gotoAndStop(nextCue);
trace("Advanced to: " + nextCue);
}
public function urlGo(event:MouseEvent, goURL:String):void {
var request:URLRequest = new URLRequest(goURL);
new URLLoader(request);
trace("Executed URL: " + goURL);
}
}
}
Problem is, once I leave frame 1, none of the buttons work... they're simply unresponsive. It seems like the code doesn't stay loaded once it leaves frame 1.
Thoughts?
I'm pressuming the problem is because when this code is first executed (as a Document Class) the only button that exists is the button on frame 1? This is under the assumption than you've created buttons in the Flash IDE then added them to the stage from the library on the specific keyframes.
I see you've created the SimpleButtons programmatically but since they haven't been added to the stage in the code you've shown, the presumption is that you've just called them the same names as the buttons you've placed on stage? Correct me if I'm wrong and I'll try to offer some other advice if the below doesn't help.
One solution would be to create them all on the first frame then switch their visibility on and off depending on when you need them.
If you're not sure how:
goto10.visible = false;
etc etc
I can't remember now without testing but if you have placed them all on the stage on different keyframes this may cause a problem.
Back in the days of putting code on the timeline if you put code on frame 1 but it referenced objects that weren't on frame 1 then the code would fail (this is probably what's happening with your document class - it's running when not all objects exist).
I would make sure they're all on one layer without any keyframes, from frame 1, and you just switch their visibility on and off. Alternatively, let your classes add and remove the buttons and other interface elements and don't use the timeline at all.

How can I change between videos faster?

I'm using the FLVPlayback component from Flash CS5 to make a videoplayer that uses an XML file as a plyalist, but I need them to play one after the other faster, at this moment it takess 1 sec or a little more to chaange to the next one.
Here is my as3 code:
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE,LoadData);
var playlist:XML = new XML();
var amountOfVideos:Number=0;
var currentVideo:Number=0;
vid.addEventListener(Event.COMPLETE, PlayNextVideo);
function LoadData(e:Event){
playlist=XML(e.target.data);
amountOfVideos=playlist.video.length();
ChangeVideo();
}
function PlayNextVideo(e:Event){
currentVideo++;
if (currentVideo < amountOfVideos){
ChangeVideo();
}
}
function ChangeVideo():void{
vid.source=playlist.video.#src[currentVideo];
}
loader.load(new URLRequest('video-list.xml'));
I know that there are some flash players that I can use, but it need to be made by me.
Thanks in advance.
You can't actually make it faster, because the 1 second you're talking about is used for loading the video.
One thing, which is not the best solution, but will help as a workaround is to have 2 FLVPlayback controls on the stage, 1 playing, 1 not visible and stopped. You'll check if the first video is getting close to its end and if so you start second video 1-2 seconds earlier and switch their visibilities.

Switch language (audio and lyric) seamlessly in Adobe Flash

I’m creating a multilingual flash game with multilingual narrations. Till now i’ve got one language with an audio stream and lyric to accompany it in it’s own timeline controlled by a button on the main timeline to pause and play. I would like to add 2 more languages with audio and own lyric(karaoke style) for each language in this scene. And eventually have buttons on the main timeline that would switch the language(audio and lyric) and seamlessly continue from where the last language left off. Till now I have this action from the main timeline controlling the audio and lyric. englyr being the movie clip, with audio and lyric in it.
toggleButton.addEventListener(MouseEvent.CLICK, toggleClick3);
toggleButton.buttonState = "off";
function toggleClick3(event:MouseEvent) {
if (toggleButton.buttonState == "on") {
englyr.play();
toggleButton.buttonState = "off";
} else {
toggleButton.buttonState = "on";
englyr.stop();
}
}
I’m assuming I should put the other 2 languages as well as their lyric in englyr so that I can disable/mute languages that are not needed to be heard or seen. One problem is I can’t group the lyric and the narration(2 layers) together as a movie clip in that timeline. Therefore cannot disable the 2 other languages that shouldn’t be heard or seen. Any solutions?
It's probably easier to let them both play from code instead of via the timeline.
The first thing to do is to go to the settings of your audioclips in the library, enable "Export for Actionscript" and set a different class name for both your clips. I have named mine "english" and "french".
The following code manages two sounds and changes the language when you press the button of a language that is currently not playing.
var englishClip:Sound = new english(); //load both sounds.
var frenchClip:Sound = new french();
//create the sound and the sound channel.
var myChannel:SoundChannel = new SoundChannel();
var mySound:Sound = englishClip;
//if you want to have lots of different languages it might be easier to just have different buttons instead of one with a state.
englishButton.addEventListener(MouseEvent.CLICK, SpeakEnglish);
frenchButton.addEventListener(MouseEvent.CLICK, SpeakFrench);
//we'll start with having just the english sound playing.
myChannel = mySound.play();
function SpeakEnglish(event:MouseEvent) {
if (mySound != englishClip) { //if the english sound is already playing, do nothing.
var currentPlayPosition:Number = myChannel.position; //save playback position.
myChannel.stop(); //stop playing
mySound = englishClip.play(currentPlayPosition); //resume playing from saved position.
}
function SpeakFrench(event:MouseEvent) {
if (mySound != frenchClip) { //if the French sound is already playing, do nothing.
var currentPlayPosition:Number = myChannel.position; //save playback position.
myChannel.stop(); //stop playing
mySound = frenchClip.play(currentPlayPosition); //resume playing from saved position.
}
This could all be made more compact by having a single function that you pass the appropriate sound to. It would look something like this:
function SpeakEnglish(event:MouseEvent) {
ChangeSound(englishClip);
}
function SpeakFrench(event:MouseEvent) {
ChangeSound(frenchClip);
}
function ChangeSound(newSound:Sound){
if (mySound != newSound) { //if the sound is already playing, do nothing.
var currentPlayPosition:Number = myChannel.position; //save playback position.
myChannel.stop(); //stop playing
mySound = newSound.play(currentPlayPosition); //resume playing from saved
}
And that should solve the problem, i hope that helped :)
Resource: http://www.republicofcode.com/tutorials/flash/as3sound/