Search code examples
flashactionscript-3flvplayback

ActionScript 3 FLVPlayBack VideoEvent


How do you add an event listener when a FLVPlayback starts? Something like below:

my_player.addEventListener(VideoEvent.COMPLETE, completePlay);
my_player.addEventListener(VideoEvent.START, startPlay);

function completePlay(e:VideoEvent):void {
my_player.seek(0);
lastFrame.addChild(lastImage);

}

function startPlay(e:VideoEvent):void {

lastFrame.removeChildAt(0);

}

What I am trying to do is load a still image when the movie completes but when the user starts the video over I want to remove the still image if it is present.


Solution

  • Your VideoEvent.COMPLETE event should be sufficient for knowing when it ends.

    For the whole starting thing I would recommend the following:

    my_player.addEventListener(VideoEvent.STATE_CHANGE, stateChanged);
    
    function stateChanged( e:VideoEvent) : void {
        if ( e.state == VideoState.PLAYING ) {
               lastFrame.removeChildAt(0);
        }
    }
    

    //Additional states that may be useful:

    VideoState.PAUSED_STATE_ENTERED
    VideoState.PLAYING_STATE_ENTERED