#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2008
    Posts
    118
    Rep Power
    6

    Simple stop FLV video script on Enter_frame


    I have a FLV video that I need to stop when my flash video reaches a certain frame.
    I named my video "SMB3video"
    Using AS3.

    I don't want something super advanced, just keep it as simple as possible.


    I tried to create a script which gave me no errors until it reached the frame for the timeline.

    Code:
    this.addEventListener(Event.ENTER_FRAME,ent_frame);
    
    function ent_frame() {
        SMB3video.stop();
    }
  2. #2
  3. No Profile Picture
    Gotta get to the next screen..
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2003
    Location
    Legion of Dynamic Discord
    Posts
    6,678
    Rep Power
    3164
    Hi, you haven't said whether you are using the FLVPlayback component or handling the video yourself. If the frame you want to stop the video on is not the the last one then you would be better off using cue points. You create those using the Flash Video Encoder which you used to create the FLV file.

    A cue point is a kind of marker you put in the video, there is nothing visual about it. In Flash you can then listen for the cue points. Each cue point can have a name so that you can then do different things depending on which cue point was just reached. A typical usage would be to play a video up to a certain point, then it hits the cue point and stops to allow the user to perform an action like answer a question or read some text in the video. Then they press play to carry on.

    As I mentioned before, you first create the cue point using the Flash Video Encoder and then you can listen for it with AS3:
    Code:
    SMB3video.addEventListener(MetadataEvent.CUE_POINT, cp_listener); 
    
    function cp_listener(eventObject:MetadataEvent):void
       { 
             SMB3video.stop(); 
       }
    You can read more about cue points here on the Livedocs page.

    Using the ENTER_FRAME event won't really help you since videos run at an independent frame rate than the rest of the Flash file. You could use the ENTER_FRAME event to keep checking the playheadTime property of the video but you won't be able to guarantee that it stops exactly when you want. That is one of the main reasons you would and should use cue points.
    Code:
    function ent_frame(event:Event):void
       {
          if(SMB3video.playheadTime >= 5000)
             {
                SMB3video.stop();
             }
       }
    Quis custodiet ipsos custodes?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2008
    Posts
    118
    Rep Power
    6
    Everything is acting weird. If I add in any of these script lines all I can is a white screen instead of the video.

    Code:
    SMB3video.addEventListener(MetadataEvent.CUE_POINT, cp_listener); 
    
    function cp_listener(eventObject:MetadataEvent):void
       { 
             SMB3video.stop(); 
       }
    BTW I added in a cuepoint named "SMB3A1" at "00:00:20:00"

    If it helps, I have two layers in my project.
    Layer2 - Many blank rows and then a PNG image at 200th frame
    FLV Videos - This has the video. I used an action script for the same frames as the video itself.

    edit: What's wrong with Enter_Frame again?
    I just stretched out the timeline and then used an action script of Enter_Frame and it stopped it right where I wanted.
    Simple and effective.
    Last edited by KingOfHeart; January 10th, 2012 at 12:38 AM.
  6. #4
  7. No Profile Picture
    Gotta get to the next screen..
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2003
    Location
    Legion of Dynamic Discord
    Posts
    6,678
    Rep Power
    3164
    The function you associate with the ENTER_FRAME event is called each frame within the Flash movie. If you are putting the code you posted, exactly as you posted it on say keyframe 20 you are effectly saying "stop" at keyframe 20 and then repeating that over and over and over. You could just put a stop() action directly on the keyframe and not bother with the ENTER_FRAME event listener.
    Quis custodiet ipsos custodes?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2008
    Posts
    118
    Rep Power
    6
    Yea, your kind of right. I'll leave it like this for now just for future reference.

IMN logo majestic logo threadwatch logo seochat tools logo