-
[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?
-
What's the code attached to the button that stops it?
-
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.
-
myStopButton.addEventListener(MouseEvent.CLICK, stopFlick);
function stopFlick(e:MouseEvent):void
{
// Choose 1 between these 4.
ns.play(false);
ns.pause();
ns.togglePause();
ns.close();
}
-
What's this:
Warning: Filter will not render. The DisplayObject's filtered dimensions (3357, 128) are too large to be drawn.
-
nevermind on the last request. It referers to my filmstrip effect.
-
-
getting this:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at index_fla::MainTimeline/streamLink()
-
Post your code (the whole thing).
-
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");
}
-
And what line is throwing the error?
-
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.
-
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");
}
-
should I use a different variable for each instance of ns?
-
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.
-
Thank you, I think this will work. If you want to see what I am doing go to fantasy-animation.com
-
Cool man. Are you just in the process of updating your site or? Cause everthing seems like it works over there.
-
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.
-
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()
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|