How to preload an swf with video? (using netconnection)
I have a swf (labeled "Video_Playback.swf") with a simple video setup: flv to net connection to net stream to video. The only movie clips on the actual stage are the play and stop buttons. This swf works just fine on it's own. However, i simply cannot figure out how to link this "Video_Playback.swf" to another .fla file.......ideally, a preloader which loads it in...
If you can take this code (from the "Video_Playback.swf")
and make it communicate properly to any .fla, i would be sooo grateful.
oh ya, here's the error message i'm getting: "Error #2044: Unhandled NetStatusEvent:. level=error, code=NetStream.Play.StreamNotFound
This is the "Video_Playback.swf" code:
var videoConnection:NetConnection = new NetConnection();
var videoStream:NetStream = new NetStream(videoConnection);
var metaListener:Object = new Object();
metaListener.onMetaData = onMetaData;
videoStream.client = metaListener;
var video:Video = new Video();
i've also included the code i'm using for my "Preloader.swf" which is having trouble loading the "Video_Playback.swf"
All of the "Video_Playback.fla" files (including the "Video_Playback.swf" & "short_jump.flv") are in a folder labeled "swfs". The only thing on the actual stage of the "Preloader.swf" is a dynamic text field with instance name of "percent"
Here's the code for my "Preloader.swf":
var l:Loader = new Loader();
var perc:Number = e.bytesLoaded / e.bytesTotal;
percent.text = Math.ceil(perc*100).toString();
percent = null;
First of all, that error you are getting is caused by not having a NetStatusEvent listener attached to the netstream object. Your code should look something like this:
I'm not entirely sure what you want the preloader to do, but if you want the preloader to preload the video file, then that's not going to happen :) Your preloader will just preload the swf containing the video file (which is probably only about 3kb, so it will load very quickly. Normally, when you use the NetStream object, the video will just start to play as soon as the buffer is full... You can set that buffer through the videoStream.bufferTime property.
So for instance if you set videoStream.bufferTime = 20; then your video will preload 20 seconds of video before actually starting to play the video. Now, setting the buffer to 20 doesn't mean that it will take 20 seconds to preload. Depending on the user's internet connection, it can take a mere 5 seconds to buffer that amount, or, if he's on a slow connection it can take up to 40 seconds or more. If you want to show a loader whenever the video is buffering, just listen to the netstatus event for the following codes: "NetStream.Buffer.Empty" (meaning that we still haven't filled our 20 second buffer) and "NetStream.Buffer.Full" (meaning that the buffer is full, and we can hide our preloader)
Now... to calculate a percentage for a buffer is quite simple. We just take the current buffer length and divide it by the bufferTime we set, and then multiply it by 100 to get the percentage. And we do this everytime we receive the "NetStream.Buffer.Empty" event code.
So that's for buffering. If for some reason, you want to preload the entire video before playing it, instead of just streaming it, then you could do that like this:
My advice to you would be to not use the Preloader.fla file, since it can just as easily be done in the playback.fla file. Also, I don't recommend preloading the entire file before playing it. Streaming is far better since a user can watch the video file almost immediately.
General notice: from now on, I would like to ask everyone to put [AS2] or [AS3] (corresponding to the version of actionscript you are using on your project) in front of their post titles when the question is actionscript related! Please help us help you faster. Thank you.
So, if i ditch the preloader.fla, how do i set this preloader up in the playback.fla?
I'm trying to build a portfolio site....
i was hoping to have a preloader on it's own .fla, which would load in a default main page (in this case the playback.swf, containing the netconnection, netstream, and video stuff) and also incorporate more buttons on the main page (playback.fla) which would load in other swfs containing different pages...this workflow seems to work fine with swfs containing galleries, graphics, and text...but like you said, the video does not come in. Just so that i'm clear on this, are you saying that you simply cannot load this playback.swf to a button, preloader, or movieclip of a separate .fla file?