AS3: How can I stop and loop FLV playback? - actionscript-3

I'm trying to make a credits page with a video playing in the background and when the menu button on screen is clicked you will be taken to the main menu and the video will stop. When debugging my app though, the following code cause it to cycle through all 5 scenes at lightspeed, not sure what causes this. I'll show you what code it likes and what code it doesn't.
Bugged code:
stop();
import fl.video.*;
import flash.events.VideoEvent;
Playback.source = "TONIGHT'S THE NIGHT.flv";
function FLVDone(event:VideoEvent):void{
event.target.stop();
}
Playback.addEventListener(VideoEvent.COMPLETE, FLVDone);
function FLVDone(event:VideoEvent):void{
event.target.stop();
}
//Menu Button
btnMenu.addEventListener(MouseEvent.MOUSE_UP, Menu5Clicked);
function Menu5Clicked (e:MouseEvent){
gotoAndStop(1)
FLVDone()
}
Working Code with no stop feature:
stop();
import fl.video.*;
import flash.events.VideoEvent;
Playback.source = "TONIGHT'S THE NIGHT.flv";
//Menu Button
btnMenu.addEventListener(MouseEvent.MOUSE_UP, Menu5Clicked);
function Menu5Clicked (e:MouseEvent){
gotoAndStop(1)
}
Here's the output
WARNING: Duplicate label, Scene=Scene 1, Layer=BG, Frame=2, Label=Credits
WARNING: Duplicate label, Scene=Scene 1, Layer=BG, Frame=3, Label=Credits
WARNING: Duplicate label, Scene=Scene 1, Layer=BG, Frame=4, Label=Credits
WARNING: Duplicate label, Scene=Scene 1, Layer=BG, Frame=5, Label=Credits
Fonts should be embedded for any text that may be edited
at runtime, other than text with the "Use Device Fonts"
setting. Use the Text > Font Embedding command to embed fonts.
this appears in both versions of the code when debugged

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 CS6, AS3 button issue

I'm using the code below to have button "legalBtn" access the layer and instance name of "legalOverlay." Then after the legalese has been read, the enduser can close the "legalOverlay" via "closeBtn" and return to the last frame of the banner ad. The code below has no compiler errors, but the "legalBtn" is still not working. Any ideas?
import flash.events.MouseEvent;
function init(){
legalBtn.addEventListener(MouseEvent.CLICK, legalClick);
legalBtn.visible=true;
legalOverlay.clickthru.addEventListener(MouseEvent.CLICK);
legalOverlay.clickthru.buttonMode=true;
legalOverlay.closeBtn.addEventListener(MouseEvent.CLICK);
legalOverlay.closeBtn.buttonMode=true;
legalOverlay.visible=false;
}
function legalClick(e:MouseEvent){
if(legalOverlay.visible==true){
legalOverlay.visible=false;
} else {
legalOverlay.visible=true;
}
}
stop();
You have to call the init() function to add the click event listener on your legalBtn object and make it visible.

Audio ActionScript 3

import flash.media.Sound;
var sound1 = new MenuTheme();
sound1.play(1000);
if(currentFrame == 2(your dedicated frame)
{
sound1.stop();
}
It comes up with Error TypeError: Error #1006 I want it to stop on the next frame after clicking a button otherwise this error stops everything :(
How to get audio to stop on next scene?
Rather than checking to see if the current frame is 2, I would suggest stopping the sound when the button is clicked, like so (with an example button named buttonToNextFrame):
buttonToNextFrame.addEventListener(MouseEvent.MOUSE_DOWN, goToNextFrame);
function goToNextFrame (e: MouseEvent) {
sound1.stop();
//Other stuff you would like done when the button is pressed.
gotoAndStop(2);
}
If there is a way to bypass the button to get to frame 2 and you still want the sound to stop, then you would have to either:
stop the sound in every event/way used to get to frame 2
stop the sound directly on frame 2 with a plain sound1.stop()
Let me know if you have any further questions!

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.

Loading movie with a button

I am trying to load movies via buttons interaction with ActionScript 3.0. I am creating this movie from Flash CS 5.5.
I could get the first button (I called 'Preface') to work. When adding the second button, I got this error at runtime:
Scene 1, Layer 'Actions', Frame 1, Line 22 1023: Incompatible override.
Scene 1, Layer 'Actions', Frame 1, Line 22 1021: Duplicate function definition.
There dun seem to be any duplicate that could initiate any overrides:
//import flash.events.MouseEvent;
preface.addEventListener(MouseEvent.CLICK, preface1);
sq.addEventListener(MouseEvent.CLICK, sq);
function preface1(event:MouseEvent):void
{
// Start your custom code
// This example code displays the words "Mouse clicked" in the Output panel.
trace("Mouse clicked");
var preface:Preface= new Preface;
addChild(preface);
preface.removeEventListener(MouseEvent.CLICK, preface1);
// End your custom code
}
function sq(event:MouseEvent):void
{
//Get sample menus
}
Any pointers is highly appreciated.
You have an instance of a MovieClip named sq, and you declare a function with name sq. This is no longer possible to do with Actionscript 3. You have to name your function something other than sq or preface, as this name is occupied by your another MC.