A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Need help unloading streaming video

  1. #1
    Junior Member
    Join Date
    Aug 2008
    Posts
    19

    Need help unloading streaming video

    I've structured my Flash site (CS4, AS3) with several movie clips to serve as containers for the content.

    sideContainer_mc contains navigation buttons;
    topContainer_mc has some identifying text;
    mainContainer_mc has the main content.

    On the main timeline, I use frame labels, and on my "Gorgon" frame, I have a streaming flv ("troll.flv") playing.

    When I use a button in my sideContainer_mc to move to a new frame on the main timeline, how do I get the streaming video troll.flv to stop playing?

    I tried creating a Boolean variable to keep track of whether or not a video was playing, and if so, added MovieClip(root).stream.stop within the click handler of my navigation buttons (so when a nav button is clicked, the video should stop as I leave that page):


    function sectionClicked (event:MouseEvent):void
    {
    if(MovieClip(root).videoPlaying == true)
    {
    trace("will try to stop video from playing!");
    MovieClip(root).stream.stop("troll.flv");
    }



    but I get ReferenceError: Error #1069: Property stop not found on flash.net.NetStream and there is no default value.
    at yourGodsMockUp5_fla::sideContainer_7/sectionClicked()


    I've pasted the code from the Gorgon frame on the main timeline so you can see how I loaded the streaming video (Note - I'd welcome any comments as to whether this is the best method; I'm pretty new at this and was surprised that no "loader" was involved)





    stop();

    var connection:NetConnection = new NetConnection();
    var stream:NetStream;
    var video:Video = new Video(600,400);

    var metaObj:Object = new Object();

    var isPaused:Boolean = true;


    function onMetaData(data:Object):void
    {

    }

    function playVideo(event:MouseEvent):void
    {
    videoPlaying=true;
    trace("videoPlaying is now " + videoPlaying);
    if(isPaused)
    {
    stream.resume();
    }
    else
    {
    stream.play("trollflv3.flv");
    }
    isPaused = false;
    }



    function pauseVideo(event:MouseEvent):void
    {
    stream.pause();
    isPaused = true;
    videoPlaying=false;
    }

    function stopVideo(event:MouseEvent):void
    {
    stream.seek(0);
    stream.pause();
    isPaused = true;
    videoPlaying=false;
    }




    connection.connect(null); //this says not using Flash Server(needs to be set; doesn't work if comment this out
    stream = new NetStream(connection); // for Progressive download
    stream.client = metaObj; //this connects the stream to metaObj to avoid asynch error
    metaObj.onMetaData = onMetaData; //so this runs the onMetaData function
    video.attachNetStream(stream);
    addChild(video);
    stream.play("trollflv3.flv")
    videoPlaying=true;
    trace("videoPlaying is now " + videoPlaying);
    //stream.pause(); use this pause if want to have movie off when enter frame
    video.x = 250;
    video.y = 175;

    play_btn.addEventListener(MouseEvent.CLICK, playVideo);
    stop_btn.addEventListener(MouseEvent.CLICK, stopVideo);
    pause_btn.addEventListener(MouseEvent.CLICK, pauseVideo);

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    connection.close();
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Junior Member
    Join Date
    Aug 2008
    Posts
    19
    Where exactly do I place this code?

    I tried putting MovieClip(root).connection.close(); in my sectionClicked handler, but it doesn't stop the video (code pasted below)

    Note - the video is actually in mainContainer_mc in the main timeline so I also tried MovieClip(root).mainContainer_mc.connection.close( ); , but when I do that, I get the following error when trying to click away from a video: TypeError: Error #1010: A term is undefined and has no properties. (and video is not removed)

    function sectionClicked (event:MouseEvent):void
    {

    if(MovieClip(root).videoPlaying == true)
    {
    trace("will try to stop video from playing!");
    MovieClip(root).connection.close();
    }

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    This should work:
    mainContainer_mc.connection.close( );
    but only when connection is declared in the first frame of that movieclip. Please don't use MovieClip(root). In AS3 you don't need this or root, because the reference is already given. You use MovieClip(root) only when you have a variable, which you cannot use with root directly.
    - The right of the People to create Flash movies shall not be infringed. -

  5. #5
    Junior Member
    Join Date
    Aug 2008
    Posts
    19
    cancerinform,

    Thanks for the help, but I still don't have this working. My video sits in mainContainer_mc off the main timeline - currently in frame 40 labeled "gorgonMain". My navigation buttons (where I have my clickHandler code) are located in sideContainer_mc which also sits in the main timeline.

    Do I need to move my Net Connection and Net Stream statements to the first frame of the main timeline? And if so, what part do I place on the first frame, and what parts do I leave on the labeled frame where I actually want to start the video?


    (I've tried a bunch of different statements in my clickHandler, and I've posted the errors I get with each of them below. Beneath that, I placed the code I'm using to open the Net Connection in the Gorgon frame of my Main Timeline).

    Thanks for your help.

    ERRORS:

    If I just put connection.close(); in my handler, I get error 1120 Access of undefined property connection,

    With mainContainer_mc.connection.close( );
    I get the error: Access of undefined property mainContainer_mc

    When I tried parent.mainContainer_mc.connection.close(); I get another error: Access of possibly undefined property mainContainer_mc through a reference with static type flash.displayisplayObjectContainer

    MovieClip(root).mainContainer_mc.connection.close( ); is the only command that doesn't give me errors, but it doesn't close the video.



    Gorgon frame in MainTimeline with video:

    stop();

    var connection:NetConnection = new NetConnection();
    var stream:NetStream;
    var video:Video = new Video(600,400);

    var metaObj:Object = new Object();

    var isPaused:Boolean = true;


    function onMetaData(data:Object):void
    {

    }

    function playVideo(event:MouseEvent):void
    {
    videoPlaying=true;
    trace("videoPlaying is now " + videoPlaying);
    if(isPaused)
    {
    stream.resume();
    }
    else
    {
    stream.play("trollflv3.flv");
    }
    isPaused = false;
    }



    function pauseVideo(event:MouseEvent):void
    {
    stream.pause();
    isPaused = true;
    videoPlaying=false;
    }

    function stopVideo(event:MouseEvent):void
    {
    stream.seek(0);
    stream.pause();
    isPaused = true;
    videoPlaying=false;
    }




    connection.connect(null); //this says not using Flash Server(needs to be set; doesn't work if comment this out
    stream = new NetStream(connection); // for Progressive download
    stream.client = metaObj; //this connects the stream to metaObj to avoid asynch error
    metaObj.onMetaData = onMetaData; //so this runs the onMetaData function
    video.attachNetStream(stream);
    addChild(video);
    stream.play("trollflv3.flv")
    videoPlaying=true;
    trace("videoPlaying is now " + videoPlaying);
    //stream.pause(); use this pause if want to have movie off when enter frame
    video.x = 250;
    video.y = 175;

    play_btn.addEventListener(MouseEvent.CLICK, playVideo);
    stop_btn.addEventListener(MouseEvent.CLICK, stopVideo);
    pause_btn.addEventListener(MouseEvent.CLICK, pauseVideo);

  6. #6
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Declare the NetConnection object in frame 1, only this line
    var connection:NetConnection = new NetConnection();
    and eliminate the declaration later. I don't know it works. AS3 is best for 1 frame movies.
    - The right of the People to create Flash movies shall not be infringed. -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center