A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 27

Thread: [RESOLVED] play video, stop video

  1. #1
    Member
    Join Date
    Sep 2009
    Posts
    32

    resolved [RESOLVED] play video, stop video

    ******My website is fantasy-animation.com******

    My videos 'stutter' when played by buttons with this simple code: player.source="externalFile.flv";

    I replaced it with the code:

    var vid:Video = new Video();
    addChild(vid);

    var nc:NetConnection = new NetConnection();
    nc.connect(null);

    var ns:NetStream = new NetStream(nc);
    vid.attachNetStream(ns);

    var listener:Object = new Object();
    listener.onMetaData = function(evt:Object):void {};
    ns.client = listener;

    ns.play("externalVideo.flv");

    ////////////////////////////////////////////////////////////////////

    Now my video works but does not stop when I click another button. How do I stop playback of each video?

  2. #2
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    What's the code attached to the button that stops it?

  3. #3
    Member
    Join Date
    Sep 2009
    Posts
    32

    stop video

    That's my question. I would like to put a code on each button that stops whatever video is playing. Right now they just play until they are finished. I would like to set them up to loop, but not until I can get them to stop on commmand.

  4. #4
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    myStopButton.addEventListener(MouseEvent.CLICK, stopFlick);

    function stopFlick(e:MouseEvent):void
    {
    // Choose 1 between these 4.

    ns.play(false);
    ns.pause();
    ns.togglePause();
    ns.close();
    }

  5. #5
    Member
    Join Date
    Sep 2009
    Posts
    32
    What's this:

    Warning: Filter will not render. The DisplayObject's filtered dimensions (3357, 128) are too large to be drawn.

  6. #6
    Member
    Join Date
    Sep 2009
    Posts
    32
    nevermind on the last request. It referers to my filmstrip effect.

  7. #7
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    Is your problem fixed?

  8. #8
    Member
    Join Date
    Sep 2009
    Posts
    32
    getting this:

    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at index_fla::MainTimeline/streamLink()

  9. #9
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    Post your code (the whole thing).

  10. #10
    Member
    Join Date
    Sep 2009
    Posts
    32
    mcScroll.mcNest.mcFilmStripButtons.bOrb1.addEventL istener(MouseEvent.CLICK, orbLink);
    function orbLink(event:MouseEvent):void
    {

    var vid:Video = new Video();
    addChild(vid);

    var nc:NetConnection = new NetConnection();
    nc.connect(null);

    var ns:NetStream = new NetStream(nc);
    vid.attachNetStream(ns);

    var listener:Object = new Object();
    listener.onMetaData = function(evt:Object):void {};
    ns.client = listener;

    ns.play("orb.flv");

    }

    mcScroll.mcNest.mcFilmStripButtons.bStream1.addEve ntListener(MouseEvent.CLICK, streamLink);
    function streamLink(event:MouseEvent):void
    {


    var vid:Video = new Video();
    addChild(vid);

    var nc:NetConnection = new NetConnection();
    nc.connect(null);

    var ns:NetStream = new NetStream(nc);
    vid.attachNetStream(ns);

    var listener:Object = new Object();
    listener.onMetaData = function(evt:Object):void {};
    ns.client = listener;

    ns.play("stream.flv");


    }

  11. #11
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    And what line is throwing the error?

  12. #12
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    The code you posted is not even relevant to your question.

    You asked how to stop a stream. I gave you code to stop the stream and that code is nowhere in what you just posted.

  13. #13
    Member
    Join Date
    Sep 2009
    Posts
    32
    sorry, here is the code that includes your suggestion, ns.close(); It is the line of code that is causing the error notice:

    mcScroll.mcNest.mcFilmStripButtons.bOrb1.addEventL istener(MouseEvent.CLICK, orbLink);
    function orbLink(event:MouseEvent):void
    {
    ns.close();
    var vid:Video = new Video();
    addChild(vid);

    var nc:NetConnection = new NetConnection();
    nc.connect(null);

    var ns:NetStream = new NetStream(nc);
    vid.attachNetStream(ns);

    var listener:Object = new Object();
    listener.onMetaData = function(evt:Object):void {};
    ns.client = listener;

    ns.play("orb.flv");

    }

    mcScroll.mcNest.mcFilmStripButtons.bStream1.addEve ntListener(MouseEvent.CLICK, streamLink);
    function streamLink(event:MouseEvent):void
    {

    ns.close();
    var vid:Video = new Video();
    addChild(vid);

    var nc:NetConnection = new NetConnection();
    nc.connect(null);

    var ns:NetStream = new NetStream(nc);
    vid.attachNetStream(ns);

    var listener:Object = new Object();
    listener.onMetaData = function(evt:Object):void {};
    ns.client = listener;

    ns.play("stream.flv");


    }

  14. #14
    Member
    Join Date
    Sep 2009
    Posts
    32
    should I use a different variable for each instance of ns?

  15. #15
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    ns doesn't exist at that point. Notice how you create ns 5 lines down?

    So therefore you "cannot access a property or method of a null object reference".

    Your problem here is that you create ns inside the button handling function. So ns only exists within the scope of that function.

    ns should be created outside the function and then it's methods called within the button handling function, like this:

    Code:
    var vid:Video = new Video();
    var nc:NetConnection = new NetConnection(); 
    var ns:NetStream = new NetStream(nc); 
    var listener:Object = new Object(); 
    
    addChild(vid);
    vid.attachNetStream(ns);
    
    listener.onMetaData = function(evt:Object):void {}; 
    ns.client = listener; 
    
    mcScroll.mcNest.mcFilmStripButtons.bOrb1.addEventListener(MouseEvent.CLICK, orbLink);
    mcScroll.mcNest.mcFilmStripButtons.bStream1.addEve ntListener(MouseEvent.CLICK, streamLink);
    
    function orbLink(event:MouseEvent):void
    {
    ns.close();
     
    nc.connect(null); 
    
    ns.play("orb.flv"); 
    
    }
    
    function streamLink(event:MouseEvent):void
    {
    ns.close(); 
    
    nc.connect(null);  
    
    ns.play("stream.flv"); 
    
    }
    Now I'm not sure what the reality of what you are trying to accomplish is but this is the basics of it.

  16. #16
    Member
    Join Date
    Sep 2009
    Posts
    32
    Thank you, I think this will work. If you want to see what I am doing go to fantasy-animation.com

  17. #17
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    Cool man. Are you just in the process of updating your site or? Cause everthing seems like it works over there.

  18. #18
    Member
    Join Date
    Sep 2009
    Posts
    32
    I am updating my site. I designed an intro that will play first then go to the main page. The current script for calling the videos works, but the video is not streaming. Sometimes it gets stuck. I am trying to resolve that.

  19. #19
    Member
    Join Date
    Sep 2009
    Posts
    32
    What's this?

    ArgumentError: Error #2126: NetConnection object must be connected.
    at flash.net::NetStream/construct()
    at flash.net::NetStream()
    at index_fla::MainTimeline/frame4()

  20. #20
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    I'm not familiar with the NetConnection class but I'm assuming this line:

    nc.connect(null);

    Should be right under this line:

    var nc:NetConnection = new NetConnection();

Tags for this Thread

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