Control FLVPlayback with events - actionscript-3

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.

Related

How to play animation and then play reverse on hover, start playing again until end on hover out using in Adobe Animate (Flash)?

Sorry this is so specific but I have combed through so many pages and videos and tutorials and can't figure this out.
I have all of my animations within a MovieClip. In the movie clip is also a stage sized white square button with the instance name "btn". Back on the main stage I have a second layer called "actions" with the following code applied to the first (and only) frame. It's not working. At all. (HUGE) tia
stop(); // this will stop the movie from playing at the start
btn.addEventListener((MouseEvent.ROLL_OVER, playMovie);
btn.addEventListener((MouseEvent.ROLL_OUT, stopMovie);
function playMovie(evt:MouseEvent):void {
play();
}
function stopMovie(evt:MouseEvent):void {
stop();
}
The problem is when you say play(); or stop(); which object are you really commanding? Your playMovie function could be in theory used to control many MovieClips at once, in different ways, so be specific with your commands...
btn.play(); //start the playback of "btn" MC
btn.stop(); //stop the playback of "btn" MC
Also consider using MOUSE_OVER/OUT instead ROLL_OVER/OUT etc but whatever works for you.
For reversing you will use btn.prevFrame(); together with an ENTER_FRAME event function. This function reads your Document settings for the FPS. For example, if you set 30 frames-per-sec then whatever instructions you put inside the event function will be processed 30 times per second.
See this other Answer for advice about reversing the playback of a MovieClip.
#VC.One is correct in how you should implement a solve to your issue, however in response to your comment on their answer, I thought I would demonstrate how to implement this fully for you - incase they don't.
var removeUpdate = false;
btn.addEventListener(MouseEvent.MOUSE_OVER, playMovie);
btn.addEventListener(MouseEvent.MOUSE_OUT, stopMovie);
function playMovie(evt:MouseEvent):void {
// Stop rewinding the movie clip and play it
if(removeUpdate){
stage.removeEventListener(Event.ENTER_FRAME, update);
removeUpdate = false;
}
// play our button
btn.play();
}
function stopMovie(evt:MouseEvent):void {
// stop our button
btn.stop();
// ... and rewind it
stage.addEventListener(Event.ENTER_FRAME, update);
removeUpdate = true;
}
function update(evt: Event){
// moves the button movie clip backwards one frame.
btn.prevFrame();
// If we have finished rewinding the movie clip, then stop
if(btn.currentFrame == 1){
stage.removeEventListener(Event.ENTER_FRAME, update);
removeUpdate = false;
}
}
It is important that you remove the update event because if you don't, the movie will never play again, because it will go one frame forward and then back again every frame due to; btn.play(); btn.prevFrame();

clickTAG and stop tag won't work simultaneously

I've created a swf banner and have added a stop(); action so it doesn't loop. As soon as I add the clickTAG to the file, the stop tag is ignored and continues to loop. I'm using Flash CC and as3. How do I get them both to work. I've done it before in older versions.
Here is my click tag:
clickTAG.addEventListener(MouseEvent.MOUSE_UP, onClick);
function onClick(e:MouseEvent):void {
var click_url:String = root.loaderInfo.parameters.clickTAG;
if(click_url) {
navigateToURL(new URLRequest(click_url), '_blank');
}
}
Here is my stop:
stop();
They are on different layers.
Are you having some output in the "COMPILER ERRORS" panel?.
please note that the code must be inserted into Actions Frame at first Frame and that you must have a transparent movie clip in the Stage with "clickTAG" as instance name.

AS3 Accessing frame without using gotoAndStop

Is there a way to access the image data (children/transformation info) of a particular frame in a MovieClip without having to use the gotoAndStop methods.
These methods are part of a rendering pipeline, all I want is access to the data, not to start a chain of asynchronous events that were developed to render things on screen, call multiple event listeners and execute frame actions.
Not only can you not do that, but gotoAndStop() doesn't even immediately make that data available. The contents of a frame aren't code accessible until the FRAME_CONSTRUCTED Event is dispatched when that frame is reached, so what you would actually have to do is more like:
var lastFrame:int = currentFrame;
function ready(e:Event):void
{
if(currentFrame !== lastFrame)
{
// In this example, frame 15 is where some image
// data we want is.
if(currentFrame === 15)
{
// Get image data.
//
}
lastFrame = currentFrame;
}
}
addEventListener(Event.FRAME_CONSTRUCTED, ready);
Needless to say; storing data you need across frames is not a viable way to structure an application.

Flash AS3 run function after Exit frame

i really need some AS3 Script for run some function when i leave a specfic frame.
my reason is to put some function to stop video and resume my sound of mp3 player AFTER i exit the frame that contain FLV playback .
i use this script and it`s work great in FLash projector but stage.invalidate(); cause the Third party application maker like Swfkit and Zinc Not responding after i try to exit from flv playback frame.
Here is my Script :
stage.invalidate();
mene.addEventListener(Event.RENDER,exitingF);
mene.addEventListener(Event.REMOVED_FROM_STAGE, removedF);
function exitingF(e:Event):void{
controller.gotoAndStop(2);
pausePosition = sndChannel.position;
sndChannel.stop();
isPlaying = false;
}
function removedF(e:Event):void{
mene.stop();
controller.gotoAndStop(1);
sndChannel = soundClip.play(pausePosition);
isPlaying = true;
}
all i need is some another way to say flash run some script right after exit specfic frame ( go to another frame )
Try using the addFrameScript() function.
It works like so: OBJECT.addFrameScript(FRAME, CALLBACK)
This will add a script to a timeline and the callback will be executed whenever the specified frame is reached.
Here's an example I found: http://blog.newmovieclip.com/2007/04/30/add-a-frame-script-addframescript-dynamically-in-flash-cs3/
package com.newmovieclip{
import flash.display.MovieClip;
public class Main extends MovieClip {
public var myStar:Star;
//constructor
public function Main() {
//place a star on stage
myStar = new Star();
addChild(myStar);
//add script to star timeline on frame 5
myStar.addFrameScript(4,frameFunction); // (zero based)
}
private function frameFunction():void {
trace("Executing code for star Frame 5" );
//delete frame script by passing null as second parameter
myStar.addFrameScript(4,null);
}
}
}
Remember that frames are 0 based as mentioned in the inline comment from the example

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....