Skip to main content
Participant
March 17, 2012
Question

help with FLVPlayback (as3)

  • March 17, 2012
  • 1 reply
  • 1805 views

Hi There,

I hope someone can save me with this.

I am currently working on a project (AS3), where I have 2 frames, with 2 videos (using the FLVPlayback component).

and I want to switch from one video to the next video, however the catch is when i switch to the next video I want the new video to play at the previous video time.

example:

Video 1 plays,  10 sec later, you click a button to go and see the next video (in another frame) and that new Video starts 10 sec into it.

This is the codes I been using so far:

------------------------------

import fl.video.VideoEvent;

import fl.video.MetadataEvent;

video1.addEventListener(VideoEvent.PLAYHEAD_UPDATE, timer);

function timer(e:VideoEvent):void {

    var newTime = video1.playheadTime;

 

};

nextFrame_btn.addEventListener( MouseEvent.MOUSE_UP, nextFrame);

    

function nextFrame (MouseEvent):void

{

                               

            gotoAndStop(2);

      video2.playheadTime = newTime;

          

                    

}

--------------------

This doesn't work and I do not know what I am doing wrong.

many thanks if you can help.

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
March 17, 2012

There are likely a couple of things that need attention with your code/design. 

The first thing I notice is that you are creating a function called "nextFrame"  Flash already has a function by that name, so there is probably a conflict arising in your doing that.

The next thing could be that you do not have video2 in frame 1 whewre I assume that code is.  The code in your nextFrame function will execute before you move to frame 2, so if your video2 object is not in frame 1, that code will produce an error.

Another thing I notice is that you have your newTime variable declared inside your timer function, but then you try to use that variable inside your nextFrame function.  newTime only exists within the function you declared it in.  If you want both functionsd to be able to use it, then you need tro declare it external to them.

Not that it is  a problem, but if you are going to use a button to trigger this then you probably do not need to have an event listener constantly updating the newTime variable.  You can just assign the playheadTime value when you click the button.

If you are seeing errors when you try to run your code then you should ciopy/paste them into your posting... it can save time trying to determine what problems might exist.

ViperCS5Author
Participant
March 17, 2012

Hi thanks for your reply.

Ok I change the names of the button, etc to stop conflicts.. so this is the code:

---------------------------------

import fl.video.VideoEvent;

import fl.video.MetadataEvent;

var newTime:int;

video1.addEventListener(VideoEvent.PLAYHEAD_UPDATE, counterX);

function counterX(e:VideoEvent):void {

    newTime = video1.playheadTime;

};

switch1_btn.addEventListener( MouseEvent.MOUSE_UP, switch1);

   

function switch1 (MouseEvent):void

{

                              

      gotoAndStop(2);

      vid1.playheadTime = newTime;

}

--------------------------------

It kind of works.. but I get these errors:

The video player is in the connection error state. It enters this state when a video stream attempted to load but was unsuccessful. There are two possible reasons for the error: no connection to the server or the stream was not found.

TypeError: Error #1009: Cannot access a property or method of a null object reference.

          at brid_fla::MainTimeline/counterX()

          at flash.events::EventDispatcher/dispatchEventFunction()

          at flash.events::EventDispatcher/dispatchEvent()

          at fl.video::FLVPlayback/http://www.adobe.com/2007/flash/flvplayback/internal::handleVideoEvent()

          at flash.events::EventDispatcher/dispatchEventFunction()

          at flash.events::EventDispatcher/dispatchEvent()

          at fl.video::VideoPlayer/http://www.adobe.com/2007/flash/flvplayback/internal::doUpdateTime()

          at flash.utils::Timer/_timerDispatch()

          at flash.utils::Timer/tick()

Ned Murphy
Legend
March 17, 2012

I have since discovered you crossposted this in the General forum and someone there offered some help.  Please don't crosspost.  Crossposting can lead to different people in different places wasting their time unnecessarily.  You should pursue the other posting you have for this.