从总共 5 个 flv 中随机播放一个 flv

发布于 2024-11-29 11:56:47 字数 675 浏览 8 评论 0原文

我需要您关于 Actionscipt3.0 的帮助。说实话我对flash实在是菜鸟。我更像是一名 3D 设计师,所以没有太多 flash ;) 目前我必须创建一个网站,其中一些视频应该自动播放。

当用户打开 URL 并登陆页面时,应播放总共 5 个随机视频。当视频播放完毕后,它应该从总共 5 个视频中选择另一个视频。

举个例子:它应该从 5 个视频中选择一个视频。播放它,然后它应该选择 4 个视频中的 1 个视频,然后它应该选择 3 个视频中的 1 个视频..等等。当所有 5 个都玩完后,它应该重复这个过程。

我希望这里有人可以帮助我......到目前为止我所拥有的是......

var 文件:Array = [ "Sz01Puppet.flv", "Sz02Puppet.flv", "Sz03Puppet.flv", "Sz04Puppet.flv", "Sz05Puppet.flv"];变量 randomFiles:Array = [];

var i:int;对于(i = 0;我 randomFiles.push(files[Math.floor(Math.random() * files.length)]); }

跟踪(随机文件);

但它没有以任何方式工作..

如果有人能帮助我那就太好了

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
randomFiles.push(files[Math.floor(Math.random() * files.length)]);
}

trace(randomFiles);

But its not working in any way..

Would be great if someone could help me out

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

各自安好 2024-12-06 11:56:47

是的,你就快到了。
下面是 for 循环的编写方式:

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)]);
trace(randomFiles);

不过,您会注意到从数组中删除了项目,因此您将有重复项。

这是一个例子:

var files:Array = [ "Sz01Puppet.flv", "Sz02Puppet.flv", "Sz03Puppet.flv", "Sz04Puppet.flv", "Sz05Puppet.flv" ];
var shuffledFiles:Array = shuffleArray(files);
//quick test
var testTimer:Timer = new Timer(1000);
testTimer.addEventListener(TimerEvent.TIMER,updateFile);
testTimer.start();

function updateFile(event:TimerEvent):void{
    if(shuffledFiles.length == 0) shuffledFiles = shuffleArray(files);//all files played, repeat process
    trace('play file',shuffledFiles[0]);
    shuffledFiles.shift();
}
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;
}

Goodluck

Yup, you're nearly there.
Here's how the for loop should've been written:

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)]);
trace(randomFiles);

Still, you're note removing items form the array, so you'll have duplicates.

Here's an an example:

var files:Array = [ "Sz01Puppet.flv", "Sz02Puppet.flv", "Sz03Puppet.flv", "Sz04Puppet.flv", "Sz05Puppet.flv" ];
var shuffledFiles:Array = shuffleArray(files);
//quick test
var testTimer:Timer = new Timer(1000);
testTimer.addEventListener(TimerEvent.TIMER,updateFile);
testTimer.start();

function updateFile(event:TimerEvent):void{
    if(shuffledFiles.length == 0) shuffledFiles = shuffleArray(files);//all files played, repeat process
    trace('play file',shuffledFiles[0]);
    shuffledFiles.shift();
}
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;
}

Goodluck

不语却知心 2024-12-06 11:56:47

您可以使用 Array.sort() 函数对其进行随机排序。

// random sort function
function shuffle(a:*, b:*):int 
{
    return int(Math.random() * 2) - 1;
}

var files:Array = ["Sz01Puppet.flv", "Sz02Puppet.flv", "Sz03Puppet.flv", "Sz04Puppet.flv", "Sz05Puppet.flv"];

var randomFiles:Array = files.sort(shuffle); // get a new instance of the array which is sorted

trace(randomFiles);

You could use the Array.sort() function to sort it randomly.

// random sort function
function shuffle(a:*, b:*):int 
{
    return int(Math.random() * 2) - 1;
}

var files:Array = ["Sz01Puppet.flv", "Sz02Puppet.flv", "Sz03Puppet.flv", "Sz04Puppet.flv", "Sz05Puppet.flv"];

var randomFiles:Array = files.sort(shuffle); // get a new instance of the array which is sorted

trace(randomFiles);
停顿的约定 2024-12-06 11:56:47

这里是一种方法。

Here is one way to do it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文