FORUMS: list search recent posts

Chose a random FLV and play it - Code

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Arvid Schneider
Chose a random FLV and play it - Code
on Aug 11, 2011 at 3:02:08 pm

Hello Forum,

I need your help with Actionscipt3.0. To be honest I am reall noob in flash. I am more a 3D Designer so not a lot of flash ;)
Currently I have to create a website where some videos should be played automatically.

When a User opens the URL and lands on the page, a random video of a total of 5 should be played. When the video is finished, it should chose another video of the total of 5 videos.

So an example: It should chose one video of 5 videos. Play it, then it should chose 1 video of 4 videos, then it should chose 1 video of 3 videos..and so on. And after all 5 are played, it should repeat the process.

I hope someone here can help me with that...What i have sofar is this..
var files:Array = [ "Sz01Puppet.flv", "Sz02Puppet.flv", "Sz03Puppet.flv", "Sz04Puppet.flv", "Sz05Puppet.flv" ];
var randomFiles:Array = [];

var i:int;
for (i=0; i<files.length; i++) {
randomFiles.push(files[Math.floor(Math.random() * files.length)]);


But its not working in any way..

Would be great if someone could help me out

Return to posts index

Arvid Schneider
Re: Chose a random FLV and play it - Code
on Aug 13, 2011 at 10:41:40 am

Cant get the code working. Isnt here someone who can figure it out?

Return to posts index

Arvid Schneider
Re: Chose a random FLV and play it - Code
on Aug 17, 2011 at 11:24:13 am

If anyone is interested. I have got the running code :)


var files:Array;
var shuffledFiles:Array;

function ready(event:Event):void{
//swf rescale setup
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
//get FlashVars - a string converted into an Array by spliting it on the , character
//if the files FlashVar is setup correctly use the data, else use default values
if(loaderInfo.parameters.files != undefined) files = loaderInfo.parameters.files.indexOf(',') > 0 ? loaderInfo.parameters.files.split(",") : [loaderInfo.parameters.files];
else files = [ "Sz01Puppet.flv", "Sz02Puppet.flv", "Sz03Puppet.flv", "Sz04Puppet.flv", "Sz05Puppet.flv" ];
shuffledFiles = shuffleArray(files);
//play the 1st video
videoPlayer.source = shuffledFiles[0];

//see when the video finished playing
function videoFinished(event:VideoEvent):void{
if(shuffledFiles.length == 0) shuffledFiles = shuffleArray(files);//all files played, repeat process
videoPlayer.source = shuffledFiles[0];//play the first video in the random list;

shuffledFiles.shift();//remove the first video from the random list (e.g. [2,0,1].shift() becomes [0,1])
function stageResized(event:Event):void{
videoPlayer.width = stage.stageWidth;
videoPlayer.height = stage.stageHeight;
function shuffleArray(source:Array,clone:Boolean = true):Array {
var output:Array = [];
var input:Array = clone ? [].concat(source) : source;//clone ? preserve orignal items by making a copy for shuffling, or not
while(input.length) output.push(input.splice(int(Math.random() * input.length-1),1)[0]);
return output;

Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 All Rights Reserved