Skip to main content
Known Participant
November 27, 2013
Answered

Randomly Load External VDO w/o Repeat the Same File while Playing

  • November 27, 2013
  • 1 reply
  • 399 views

Hey! I have nearly done programming my Flash file. But, I'm so tired of making it not repeat the VDO file it is playing.

I hope that you guys will have that solution for me. *()*

This is my source code

////////////To Load any VDO///////////////

import flash.net.NetStream;

import flash.net.NetConnection;

import flash.media.Video;


var video;

var nc;

var ns;


nc = new NetConnection();

nc.connect(null);

ns = new NetStream(nc);

ns.client = this;

video = new Video(550,400);

addChild(video);

video.attachNetStream(ns);


///////////////////////////


/////////////Array for VDO Files/////////////

var VdoStore:Array = new Array("westler.flv","TomAndJerry.flv","GetThere.flv");


///////////////////////////


/////////////Keyboard and Screen Show////////////////

import flash.events.KeyboardEvent;

import flash.events.Event;


stage.addEventListener(KeyboardEvent.KEY_DOWN,onDown);

stage.addEventListener(KeyboardEvent.KEY_UP,onUP);




function onDown(e:KeyboardEvent):void{

var SelectedVid = VdoStore[Math.floor(Math.random() * VdoStore.length)];

//var DontRepeat:Array = new Array(); << I tried create another array to keep the file which was played


if (e.keyCode==49)

{

ns.play(SelectedVid);

stage.removeEventListener(KeyboardEvent.KEY_DOWN,onDown);

//onUP(null);

}

if (e.keyCode==69)

{

ns.play(SelectedVid);

stage.removeEventListener(KeyboardEvent.KEY_DOWN,onDown);

//onUP(null);

}

}

function onUP(e:KeyboardEvent):void

{

if(e.keyCode==49)

{

stage.addEventListener(KeyboardEvent.KEY_DOWN,onDown);

}

if(e.keyCode==69)

{

stage.addEventListener(KeyboardEvent.KEY_DOWN,onDown);

}

}

And thst is the code that I have removed all the things I have experimented out. Only the code that is working is shown above.

I don't need them all to be played before start new random. Just That, it shouldn't play the same vdo that is playing at the moment when I click any button after.

FYI,I will add more vdos, about 20, and more keyboard buttons to click as the same numbers.

Anyone? **Pleaseeeeeeee >///<

This topic has been closed for replies.
Correct answer Ned Murphy

One way would be to remove the played video from the array when it is played so that it cannot be licked again.

Another way, since you don't mind a repeat later on, would be to store the index of the selected video when it is played in a variable that you compare to the selected index.  If the selection matches the variable then you run the selection processing again until you successfully pick another video.  To do this it will be easier to have a separate function that does the selection.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
November 27, 2013

One way would be to remove the played video from the array when it is played so that it cannot be licked again.

Another way, since you don't mind a repeat later on, would be to store the index of the selected video when it is played in a variable that you compare to the selected index.  If the selection matches the variable then you run the selection processing again until you successfully pick another video.  To do this it will be easier to have a separate function that does the selection.