PDA

View Full Version : Play Random FLVs - 1st Post


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