PDA

View Full Version : flvs from an array...


flying squirel
05-24-2007, 09:00 AM
I have 5 nested video clips and I want to load in 5 external flvs. Ive set up the array. This code works for jpegs and swfs but im not sure where to enter the
var my_nc:NetConnection = new NetConnection();
my_nc.connect(null);
var my_ns:NetStream = new NetStream(my_nc);

here is my current code.

stop();

/********* DECLARE AND INITIALIZE VARIABLES **************************/
// names of folder and pictures, in the order to put them into the thumbnails holder
var vidnames:Array = [
"vid1",
"vid2",
"vid3",
"vid4",
"vid5"];

// constants
var PICPATH:String = "video/"; // folder with jpgs
var NPICS:Number = picnames.length; // number of pictures to load
var PICX:Number = 10; // x loc of big picture
var PICY:Number = 10; // y loc
var THUMBHOLDERX:Number = 0; // x location of thumbnail holder movieclip
var THUMBHOLDERY:Number = 230; // y location
var THUMBW:Number = 90; // width of each thumbnail
var THUMBH:Number = 90; // height


var totalloaded:Number = 0; // running tally of bytes loaded from all pics

// index into pictures array, used for loading
var ipic:Number;

// set up loader, an instance of MovieClipLoader
var loader:MovieClipLoader = new MovieClipLoader();

// use the main timeline to listen to and respond to loader's broadcast events
loader.addListener(this);

/********* DEFINE FUNCTIONS, INCLUDING INIT FOR MOVIE SETUP **********/
// thumbnail rollover handler

function grow() {
this.onEnterFrame = function() {
if (this._width < THUMBW * 1.2) {
this._x -= this._width * .025;
this._y -= this._height * .025;
this._width *= 1.05;
this._height *= 1.05;
} else delete this.onEnterFrame;
};
}

// thumbnail rollout handler

function shrink() {
this.onEnterFrame = function() {
if (this._width > THUMBW) {
this._width /= 1.05;
this._height /= 1.05;
this._x += this._width * .025;
this._y += this._height * .025;
} else delete this.onEnterFrame;
};
}


// thumbnail click (onrelease) handler

function openPic() {
video_holder_mc.video_mc.attachMovie(PICPATH + vidnames[this.i] + ".flv");
}






// assign event handlers (called when all jpgs are loaded)

function setupHandlers() {

thumb_holder_mc.preview_holder.preview_mc.attachMo vie(PICPATH + vidnames[Math.floor(Math.random()*2)] + ".flv");
for (var i:Number = 0; i < NPICS; i++) {
thumb_holder_mc["th"+i].onRollOver = grow;
thumb_holder_mc["th"+i].onRollOut = shrink;
thumb_holder_mc["th"+i].onRelease = openPic;
}
}



function onLoadInit(_mc:Video) {
// this gets done when the jpg is completely loaded:

// now load the next one (if there are more) or set up handlers if done
ipic++;
if (ipic == NPICS) {

setupHandlers();
} else {
loader.loadClip(PICPATH + vidnames[ipic] + ".flv", thumb_holder_mc["th"+ipic].thumb_mc);
}
};






function init() {

ipic = 0;
// start loading vids
loader.loadClip(PICPATH + vidnames[ipic] + ".flv", thumb_holder_mc["th"+ipic].thumb_mc);

}

/********* CALL THE INIT FUNCTION TO START THE MOVIE *****************/
init();

astgtciv
05-24-2007, 09:09 AM
Welcome to as.org, flying squirel!

You only need one NetStream, when you get a new flv url, call


my_ns.close(); // close the previous stream
my_ns.play(flvURL);


Note that you will probably need to attach your NetStream to a Video object as exemplified in the attachVideo doc (http://livedocs.adobe.com/flash/mx2004/main_7_2/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Flash_MX_2004&file=00001873.html).

flying squirel
05-24-2007, 09:21 AM
im not sure what you mean there. I have 5 empty clips on the stage and want to load them in so they are all playing as thumbnails. I think the loading iteration is okay but im not sure where (either in the timeline code or searately in each of the 5 empty clips) to put the netstream and the video code.

Thanks for the quick reply, much appreciated.

astgtciv
05-24-2007, 09:46 AM
Ah, I see, you want 5 flv's to be playing concurrently!

OK, you will need to have a Video object inside a MovieClip, let's say its instance name is "embVideo". See this link http://www.quip.net/blog/2006/flash/how-to-load-external-video for how to create it. An easy way to do what you are trying to do is to have this code in the first frame of your MovieClip:


var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
embVideo.attachVideo(ns);
ns.play(this.flvURL);


Now, when you do attachMovie on the embVideo-containing MovieClip (let's say its linkage id is "VideoPlayer"), you specify the "flvURL" parameter as part of initialization:


this.attachMovie("VideoPlayer", "videoPlayer1", this.getNextHighestDepth(), {flvURL: "http://myserver/myflv.flv"});


So, you can just attach the VideoPlayer 5 times, each time providing a different flvURL, and positioning the VideoPlayer each time the way you want. They should all start to play as soon as they are created (even though streaming 5 videos concurrently might be a bit of a load on the bandwidth).

flying squirel
05-24-2007, 10:43 AM
Ok so I'll put it this way:

Do i need to make a new netconnection and netstream for each movie clip and video? if the following makes sense kinda you will know what im trying to do

This is just piffle code, it probably makes no sense. umm sorry :)

so i have an array with 5 video references. so


vidnum =5;

function setupVideo {

for (var i = 0, i < vidnum; i++) {

nc[i] = new NetConnection();
nc[i].connect(null);

ns[i] = new NetStream();
my_videoholder["video" + i].attachVideo(ns[i]);
ns[i].bufferTime(0);
ns[i].play(arrayname + ".flv");

}

}


This looks way off but i hope you see what im looking for. Man its great to get some help.... thanks a bunch.

astgtciv
05-24-2007, 11:27 AM
Yeah, that looks about right, but should be


ns[i] = new NetStream(nc[i]);


If you want 5 videos to play concurrently then yes, you will need 5 NetStreams.

zerobars
07-17-2007, 07:28 PM
If you have a video embedded in a MovieClip, and then attach multiple movie clips, do you need to have actual separate NetStream objects, as in this example?

var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
embVideo.attachVideo(ns);
ns.play(this.flvURL);

or do you need to assign different NetStreams (somehow) to the embedded videos in each attached MovieClip, thus:

ns[i] = new NetStream(nc[i]);