PDA

View Full Version : [AS3] return to frame 1 on flv playback completion


dvine
05-17-2010, 02:09 AM
Guys,

I have seriously tried my best (I believe) at getting this to work. Simple for most I suspect. But I just cannot get it to work the way it needs to work.

It is a simple play button on frame 1. Once the button is pressed the video plays. I need it to return to frame 1 on flv playback completion.

The best result I have gotten thus far is playback of the FLV with it not returning to frame 1.

Please shed some light, I am stressing and pulling my hair out not knowing what is wrong.

I donít know if the VideoEvent function is working or not. When I do the declare the video_mc outside of a function the video plays in the background (you can only hear the audio). This is the reason I initially declared the video_mc variable inside of the MouseEvent function as this works fine. I am not sure if this is the correct way of doing it, but it works in my instance.

stop();
import fl.video.VideoEvent;

playBtn.addEventListener(MouseEvent.CLICK, startVideo);
video_mc.addEventListener(VideoEvent.COMPLETE, onVideoComplete);

function startVideo(event:MouseEvent):void
{
var video_mc:video = new video();
addChild(video_mc);
trace("video_mc working");
}

function onVideoComplete(event:VideoEvent)
{
gotoAndStop(1);
trace("restart function working");
}


Thank for any assistance in advance.

Cheers...

dvine
05-18-2010, 04:56 AM
OK guys. It looks like nobody knows how to get this working.

I have played a bit more but now I simply cannot get the flash piece to go back to frame 1 when the FLVPlayBack is completed. The audio issues has been corrected. I do not know how I did but something I changed fixed it.

Here is the AS on frame 1


stop();

var play_btn = new myBTN();
play_btn.addEventListener(MouseEvent.CLICK, gotoNextFrame);
addChild(play_btn);

function gotoNextFrame(event:MouseEvent):void
{
play_btn.alpha = .0;
gotoAndStop(2);
}


Here is the AS on frame 2


stop();
import fl.video.*;

var video_mc:video = new video();
video_mc.addEventListener(VideoEvent.COMPLETE, onVideoComplete);
addChild(video_mc);

function onVideoComplete(event:VideoEvent)
{
gotoAndStop(1);
}


I hope somebody here knows how to get this working.

dvine
05-18-2010, 06:23 AM
Nevermind guys. I realised what I was doing wrong. Because I created another instance/symbol of the flv component and created it as a movieclip, the flvplayback component was not handling the video so the event would not be recognised or whatever the correct terminology is.

Renamed the FLVPlayback component and changed the variable names in code like this.

Now all seems to be functioning correctly.

Frame 1


stop();

var playBtn:myBTN = new myBTN();

playBtn.x = 290;
playBtn.y = 172;
playBtn.width = 45;
playBtn.height = 55;

playBtn.addEventListener(MouseEvent.CLICK, gotoNextFrame);

addChild(playBtn);

function gotoNextFrame(event:MouseEvent):void
{
playBtn.visible = false;
gotoAndStop(2);
}


Frame 2


import fl.video.*;

stop();

var myVideo:FLVPlayback = new FLVPlayback ();

myVideo.source = "myVideo.flv"
myVideo.x = 0;
myVideo.y = 0;
myVideo.width = 600;
myVideo.height = 400;

addChild(myVideo);

myVideo.addEventListener(VideoEvent.COMPLETE, onVideoComplete);

function onVideoComplete(event:VideoEvent):void
{
gotoAndStop(1);
}


Just posted these details in case some flash/actionscript noob douche bag like me runs into the same problem.

On another note: The flv is about 13mb and the swf is 97kb. Should I be creating a pre-loader for the flv?

Cheers.