FORUMS: list search recent posts

Play video at a certain frame and loop it [AS3][FLVComponent]

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Bernat Olives
Play video at a certain frame and loop it [AS3][FLVComponent]
on Jan 15, 2013 at 2:36:08 pm

Hi all,

I'm trying to achive some functionality on my flash file but I think I'm missing few things, let's see if someone can help me:

I have a Movieclip that contains a movieclip with an animation and a FLV component that holds a video loaded externally.

The objective is to play the video in between the Movieclip animation and when that animation starts again, play again as well the video.

At the point where I am, the video only play once, but after the animation starts again, the video seems to not be available anymore.. or there's some error on the Event Listener I'm using to play again the video.

Inside the animation I have that code:


function playLoop(){
(this.parent as MovieClip).myVid.play("video.flv");
};

this.addEventListener(Event.ENTER_FRAME, playLoop);


That code play the video once, as I said. But the next time the animation goes trough that frame, the video doesn't start again.

Notice that I have a Cue Point listener that reads the cuepoints. Using that, at the end of the video I stop it and seek to 0 (after that starts again the animation).

Does anyone realise why the video doesn't play after the first time was called?

Any help will be apreciate, thank you!


Return to posts index

demetri tashie
Re: Play video at a certain frame and loop it [AS3][FLVComponent]
on Jan 15, 2013 at 7:17:34 pm

i am afraid i can not exactly follow you from your explanation.

however, you should be able to do what i think you want, by using both Event.ENTER_FRAME, and VideoEvent.COMPLETE.

a few other points: do not place your code inside of movieclips. keep all of your code at the root of the project. it is best to keep the code at the top level and target clips and nested clips downwards, referencing them directly (it is always easier, to call downwards to clips rather than back up…).

if you want you can look at this simple .fla which should be able to be reworked for your purpose.

5233_archive.zip

the full code is:import flash.events.MouseEvent;
import flash.events.Event;
import fl.video.VideoEvent;

mc1.mc2.stop();

mc1.myVid.source="lucy.flv";
mc1.myVid.stop();

startBtn.addEventListener(MouseEvent.CLICK, beginPlay);
function beginPlay(e:MouseEvent):void {
mc1.mc2.play();
mc1.mc2.addEventListener(Event.ENTER_FRAME, beginVid);
startBtn.removeEventListener(MouseEvent.CLICK, beginPlay);

}

function beginVid(e:Event):void {
if(mc1.mc2.currentFrame==mc1.mc2.totalFrames)
{ mc1.myVid.play();
mc1.mc2.stop();
mc1.mc2.removeEventListener(Event.ENTER_FRAME, beginVid);
mc1.myVid.addEventListener(VideoEvent.COMPLETE, beginAgain);
};
}

function beginAgain(e:VideoEvent):void {
mc1.mc2.play();
mc1.mc2.addEventListener(Event.ENTER_FRAME, beginVid);

}


where 'mc1' is a movieclip which has inside of it 'mc2' which is a movieclip with an animation. it also has 'myVid' which is an FLV Playback Component.

outside of 'mc1' is a button 'startBtn' which begins the whole sequence.

i hope that helps out


Return to posts index

Bernat Olives
Re: Play video at a certain frame and loop it [AS3][FLVComponent]
on Jan 16, 2013 at 10:07:02 am

Thank you Demetri for that extense explanation!

I'd explained my self wrong due my english, excuse me :_)

I've got my video already playing, the problem is that only play the first time the animation play. When the animation loop (start again from the beginning) the video doesn't play again..

My timeline starts with 4seconds of animation, then starts a video for other 4seconds and after the video ends the animation stills running for other 3 seconds and achieve the end of the whole animation. After that, starts again from the beginning, but the video will be not played again.

The video needs to start when the animation achieve the specific frame not why any other interaction like the MouseEvent, a button or the end of the video itself.

Using an ENTER_FRAME event listener I was trying to achieve that: play the video everytime the timeline run that specific frame.

But as I said seems the video doesn't rewind or simple desapear...

Well, seems a tricky issue. Thanks for your reply anyway ;)


Return to posts index


Bernat Olives
Re: Play video at a certain frame and loop it [AS3][FLVComponent]
on Jan 16, 2013 at 3:39:05 pm

Well finnaly I've solved the issue. I'm going to try a proper explanation:

I was playing a video with an FLV component. When the whole animation was playing again as a loop, the video doesn't.

I've realised that when you load and play a video into the FLV Component it keeps loaded then in the case of the loop the only action needs to be done is to play the video element without loading again the movie.

Inside the animation I've put that piece of code, first to load and then to just play the video is already loaded:


MovieClip(root).myVid.play(MovieClip(root).MainVideo);
MovieClip(root).myVid.play();


The code that didn't work on the same frame was (didn't work cause was playing the video just once):


MovieClip(root).myVid.play(MovieClip(root).MainVideo);


And with a Cue point or a VideoEvent listener I'd stoped the video and rewind to 0.


myVid.addEventListener(MetadataEvent.CUE_POINT, cp_listener);

function cp_listener(eventObject:MetadataEvent):void
{
obj = eventObject.info.parameters;
for (prop in obj)
{
//trace(prop+" "+val);
//CuePoints value;
val = obj[prop];
if (prop == "start")
{

}
else if (prop == "end")
{
trace("Video ends");
myVid.stop();
myVid.seek(0);
}//end if

}//en for
}


Anyway, already solved =)


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]