FLVPlayback Event.Complete not detecting video ending - actionscript-3

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!

Related

Adobe Flash CS6 - FLVPlayback Start From Time

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.

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

Control FLVPlayback with events

Hi im trying to use the FLVPlayback function in a emagazine flippage
and i can get the FLV to play if i remove all the code from the flash file then its starts and plays .
but i need it to be controlled by the code that i posted under here
When the magazine loads i need the flash movie to stop or pause when the viewer gets to the page where this film is located its sends a signal startAnimation4 and it should start playing the flash movie including the FLVPlayback , if the viewr flips to next page there is a event called onpageLeave that send the signal stopAnimation4 and the flash film and FLVPlayback should pause or stop.
Is there some one that have a idea of how i can do this ?
//Prevent automatic playback
stop();
FLVPlayback.pause();
//Import eMagStudio AS3 API
//import SWFHolderAPI.*;
//Initiate the EMSMediator class
EMSMediator.instance.init(this, eMagListener);
//Set variable that controls playing when the clip is called using playonce
if(playedOnce == undefined){
var playedOnce:Boolean = false;
}
//Callback function for events in the eMag. Responds to the broadcasts startAnimation and stopAnimation
function eMagListener(event:MessageEvent):void{
//Broadcast coming from eMagStudio
var eMagBrdcast:String = String(event.message);
if(eMagBrdcast == "startAnimation4"){
setTimeout(myFunction, 800);
function myFunction() {
play();
}
}else if(eMagBrdcast == "startAnimationOnce4"){
if(!playedOnce){
playedOnce = true;
play();
}
}
if(eMagBrdcast == "stopAnimation4"){
stop();
}else if(eMagBrdcast == "stopAnimationOnce4"){
if(!playedOnce){
playedOnce = true;
stop();
}
}
}
I think that your best approach here would be to create a custom event class for the page flipping events if possible. That way you can pass the video player object through the custom event class when the pageflip events are triggered so that you can instruct them what to do (i.e. play, stop, etc.) So basically, if you do have control of the dispatching of the page flip events, you would create the event object, assign the movie player component instance to a variable in the event object you instantiated, and then dispatch the event with the event object you just created.
Also, if memory serves me right, isn't FLVPlayback the name of the component used to provide FLV Player Controls? Are you using that same name as the instance name of your video players that you have added to the stage? If so, I would not do that and instead rename them to something else.

AS3 Getting to Control Stage

I am building a Flash Game, I am doing this:
MainStage, with 11 frames
Mainstage Loads > Lobby.swf (1 frame)
Lobby Loads > Arrows.swf (1 frame)
I just want to control the main Stage from Arrows.swf , get the current frame, right arrow mainStage.current frame + 1, left arrow mainStage.current frame -1
I have tried the parent/child method
this.parent.parent
parent.parent
this.root
parent.root
every combination, I am also tracing and when I finally hit the mainStage it is saying cannot convert Stage to Display Object which I understand.
but how can I just get current frame of the "mainstage" needle and control it with gotoAndPlay or other such methods ?
I have solved it.
I didn't control the main stage what I did was, I reduced the main stage layer in the lobby layer when I load the left and right arrow I attach an event listener for a custom event.
In the arrows movie I have written a function to dispatch the event here are the lines of code I used
in the "main" stage of the movie you want to control:
//ball loader prep and load
var ballLoader:Loader = new Loader();
var ballRequest:URLRequest = new URLRequest("lobbyBalls.swf");
ballLoader.load(ballRequest);
ballLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, ballsLoaded);
function ballsLoaded(event:Event):void{
trace("ball Loader complete");
ballLoader.x = 50;
ballLoader.y = 200;
stage.addChild(ballLoader);
ballLoader.content.addEventListener("Previous", ctrlPrevFrame);
ballLoader.content.addEventListener("Next", ctrlNextFrame);
}
In the movie from which you want to control
import flash.events.Event;
leftArrow.addEventListener(MouseEvent.CLICK, prevEvent);
rightArrow.addEventListener(MouseEvent.CLICK, nextEvent);
function prevEvent(event:Event):void{
trace("prev");
dispatchEvent(new Event("Previous", true));
}
function nextEvent(event:Event):void{
trace("next");
dispatchEvent(new Event("Next", true));
}
Thanks anyways....

Action Script 2 Suggestion

I am doing a project which is about interacting, mouse on screen, Hence, I want to do it by using Adobe Flash Pro and Action Script2.
here is the Task:
- a simple animations (for example: that full of spiders walking/jumping from up to down on the screen)
- once the mouse moves, the animation will Reverse (all spiders animation will reverse back and hide back to the top of screen from the place that the came).
- if the mouse doesn't move after 60 Seconds the animation will happen again till the mouse move again on the screen (Those spiders animation will happen again).
i have created a Animation Spider "Movie clip" (spider animation going down)
1- what script i should write to make animation reverse?
2- how can i tell Adobe my mouse is moved or it's not moving, so the spiders animation will happen or reverse?
by the way, I am a very beginner in action script 2.0
i appreciate any suggestion and help *is fine for me to do it in action script 3 too
Thanks.
Oh my. AS2 :)
OK first off I think it would be easier if you would create 2 different animations. One for the Spider to walk down. The other one to walk up. It is possible to reverse a MovieClip but I think if you`re a beginner, stick with the basics.
You need 3 thinks here.
1) Spider Clips. Going down and up.
2) An interval (timer in AS3)
var interval:Number = setInterval(spidersComeOut, 60 * 1000);
3) Mouse move listener
root.onMouseMove = function()
{
//swap your spider clips
//move the spider up again
//reset the interval with clearInterval(interval) and restart it again.
}
This is a very basic handler for mouse move.
Hope this will help you a little bit. This is not a complete solution. It will not work out of the box.
One thing at the end. If you are new to AS2 I would recomend to give as3 a shot. It is more difficult to start with, but there are more people out there willing to help with an AS3 problem then with as2.
Since you said you were ready to use AS3 here is solution.
I assume you have a separate movie clip containing your spiders animation which you place on the main timeline/stage.
1.place your MovieClip on the stage and give it the instance name of 'spiders'.
2.inside this MovieClip, on the first frame put this code (it will handle revesing the animation)
import flash.events.Event;
stop();
var _dir:int = 1;
addEventListener(Event.ENTER_FRAME, onEF);
function onEF(e:Event):void
{
getNextAnimationFrame();
}
function getNextAnimationFrame():void
{
var frameNum:int = currentFrame + _dir;
if (frameNum < 1 || frameNum > totalFrames)
{
removeEventListener(Event.ENTER_FRAME, onEF);
}
frameNum = Math.max(1, Math.min(totalFrames,frameNum));
gotoAndStop(frameNum);
}
function changeDirection($dir:int):void
{
_dir = $dir;
removeEventListener(Event.ENTER_FRAME, onEF);
addEventListener(Event.ENTER_FRAME, onEF);
}
3.on the main timeline (in the first frame) put this code:
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
var timer:Timer = new Timer(60 * 1000, 1);
timer.start();
timer.addEventListener(TimerEvent.TIMER_COMPLETE, onTime);
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
function onTime(e:TimerEvent):void
{
trace("it's time");
spiders.changeDirection(1);
}
function onMove(e:MouseEvent):void
{
timer.reset();
timer.start();
spiders.changeDirection(-1);
}
It would be possible to handle mouse, timer and animation in one piece of code, however the way it's build now is kind of OOP, if at some point you decided to build it properly it would be extremely easy to 'rewrite' this code as separate classes.