View Full Version : Play Random FLVs
ray_stantz
09-21-2007, 04:43 PM
Hi everyone,
I have come up against a problem, i am not great with action script so i was hoping you could help.
I have a variety of FLV files I wish to playback randomly within my Flash web site, so every time the page loads it could load any of the 6 files for example. I have created a MC for them to playback within, how can i use action script to select one of the files located in a folder at root and play it?
Its my first post and I am quite new to Flash, using Flash 8 Professional.
I look forward to hearing from you,
Raymond.
mikenaman
10-02-2007, 11:45 AM
Hi
I presume your working in AS2.0 since you have Flash 8 Pro. Here goes...
//--CREATE AN ARRAY TO STORE THE NAMES OF YOU VIDEO FILES
var videoArray:Array = new Array()
//--PUSH THE STRING VIDEO NAMES IN TO THE ARRAY
videoArray.push("videoName1")
videoArray.push("videoName2")
videoArray.push("videoName3")
videoArray.push("videoName4")
videoArray.push("videoName5")
videoArray.push("videoName6")
trace("videoArray: "+videoArray)
//--CREATE A NET CONNECTION
var connection_nc:NetConnection = new NetConnection();
connection_nc.connect(null);
//--CREATE A NETSTREAM TO PLAY YOUR VIDEO
var stream_ns:NetStream = new NetStream(connection_nc);
//--my_video IS A VIDEO SYMBOL CREATED IN THE LIBRARY
my_video.attachVideo(stream_ns);
//--TO CREATE A VIDEO SYMBOL GOTO THE LIBRARY AND CLICK THE
//--MENU BUTTON (TOP RIGHT), GOTO New Video... THIS CREATES THE
//--VIDEO SYMBOL. DRAG THE VIDEO SYMBOL TO THE STAGE AND GIVE IT
//--AN INSTANCE NAME OF my_video
//--SELECT A RANDOM VIDEO FROM THE videoArray
var tempVideo:String = videoArray[random(videoArray.length)]
//--TELL YOUR VIDEO TO PLAY
stream_ns.play(tempVideo);
I've not tested it but it should work.
Hope this helps
ray_stantz
12-14-2009, 04:56 PM
Thanks for the response. Yes it is AS 2.0.
Sadly I am still not able to achieve what I want. I have simplified things down a bit so that the bg is now an image, but I cant get it to load randomly.
Well, I can when i use:
on (release) {
choice = Math.round(Math.random()*5);
switch (choice) {
case 0 :
pic.loadMovie("image0.jpg");
break;
case 1 :
pic.loadMovie("image1.jpg");
break;
case 2 :
pic.loadMovie("image2.jpg");
break;
case 3 :
pic.loadMovie("image3.jpg");
break;
case 4 :
pic.loadMovie("image4.jpg");
break;
case 5 :
pic.loadMovie("image5.jpg");
break;
}
}
However the mc pic is designed to scale up, using the following:
//set stage for FBF
Stage.align = "TL";
Stage.scaleMode = "noScale";
//define dynamic aspect ratios
picHeight = new Object ();
picHeight = pic._height / pic._width;
picWidth = new Object ();
picWidth = pic._width / pic._height;
//conditional statement to account for various initial browswer sizes and proportions
if ((Stage.height / Stage.width) < picHeight) {
pic._width = Stage.width;
pic._height = picHeight * pic._width;
} else {
pic._height = Stage.height;
pic._width = picWidth * pic._height;
};
//center picture on stage
pic._x = Stage.width / 2;
pic._y = Stage.height / 2;
// create listener
sizeListener = new Object();
// make listener change picture size and center picture on browser resize
sizeListener.onResize = function() {
if ((Stage.height / Stage.width) < picHeight) {
pic._width = Stage.width;
pic._height = picHeight * pic._width;
} else {
pic._height = Stage.height;
pic._width = picWidth * pic._height;
};
pic._x = Stage.width / 2;
pic._y = Stage.height / 2;
}
//add listener to stage
Stage.addListener(sizeListener);
I cant seem to get them to work together, any thoughts? Thanks again!
...FLV files I wish to playback randomly ... every time the page loads
(09-21-2007, 04:43 PM)
Thanks for the response. Yes it is AS 2.0. Sadly I am still not able to achieve what I want.
(12-14-2009, 04:56 PM)
:p Glad you got back and responded 2 years later. ;-)
The only thing I see in that code provided by mikenaman that would cause it not to work (if you followed and understood the comments provided) is you need to add the .flv extension either to your array item names...
videoArray.push("videoName1.flv");
// then later...
stream_ns.play(tempVideo);
or add it instead like so...
videoArray.push("videoName1");
// then later...
stream_ns.play(tempVideo+".flv");
One or the other, otherwise if you followed the comments it should work fine.
I have simplified things down a bit so that the bg is now an image, but I cant get it to load randomly.
Give this a try its somewhat modified based on the code you provided. I changed somethings but it should do what you want....
Code is in your other thread (since the info is not really related):
Random BG Image +Full Screen
http://www.actionscript.org/forums/showthread.php3?t=225524
debugging can take a while ...
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.