...

View Full Version : Actionscript 3 videos onLoad random playback



Christina Knapp
05-12-2009, 10:58 PM
I have a simple .swf file that plays 5 videos in one playback component. I was wondering if I can get the .swf onLoad to pick randomly one of the 5 videos to start playing and have it pick a different video each time. So that way each time someone loads the page they see a different video playing. Any help would be awesome!

gnomeontherun
05-13-2009, 10:28 AM
Do you have any code now? It would just be picking a random value or randomly sorting the array of videos.

Christina Knapp
05-14-2009, 02:38 PM
The code I have on there now is just for the buttons that bring up the video. If you want to take a look at the flash itself you can go to: http://tbtheagency.com/christina/arrow -- On the .swf right now I don't have the videos set to automatically play.

I haven't tried to figure out anything on getting the videos to randomly play, honestly not sure where to begin on that and I couldn't look up anything on the web to help out cause I am not sure what I'm looking for.


var buttonsArray:Array = [btn_vid1, btn_vid2, btn_vid3, btn_vid4, btn_vid5];

function setButtons():void {
for (var i:int=0; i<buttonsArray.length; i++) {
buttonsArray[i].id = i;
buttonsArray[i].buttonMode = true;
buttonsArray[i].mouseChildren = false;
buttonsArray[i].mouseEnabled = true;
buttonsArray[i].addEventListener(MouseEvent.ROLL_OVER,playOver);
buttonsArray[i].addEventListener(MouseEvent.ROLL_OUT,playOut);
buttonsArray[i].addEventListener(MouseEvent.CLICK,doClick);
}
}

function playOver(event:MouseEvent):void {
event.currentTarget.gotoAndPlay("over");
}

function playOut(event:MouseEvent):void {
event.currentTarget.gotoAndPlay("out");
}

function doClick(event:MouseEvent):void{
var currentBtn:int = event.currentTarget.id;
setSelectedBtn(currentBtn);
}
function setSelectedBtn(id:int):void{
for (var i:int=0; i< buttonsArray.length; i++) {
if (id == i) {
buttonsArray[i].gotoAndStop("down");
buttonsArray[i].buttonMode = false;
buttonsArray[i].mouseEnabled = false;
buttonsArray[i].removeEventListener(MouseEvent.ROLL_OVER,playOver);
buttonsArray[i].removeEventListener(MouseEvent.ROLL_OUT,playOut);
buttonsArray[i].removeEventListener(MouseEvent.CLICK,doClick);
} else {
if(buttonsArray[i].currentLabel =="down"){
buttonsArray[i].gotoAndPlay("out");
}
buttonsArray[i].buttonMode = true;
buttonsArray[i].mouseEnabled = true;
buttonsArray[i].addEventListener(MouseEvent.ROLL_OVER,playOver);
buttonsArray[i].addEventListener(MouseEvent.ROLL_OUT,playOut);
buttonsArray[i].addEventListener(MouseEvent.CLICK,doClick);
}
}
}
setSelectedBtn(0);
setButtons();

function showVid1 (evt:MouseEvent): void{
vidComp.source = "videos/Arrow Fireworks_NoBars.flv";
}
btn_vid1.addEventListener (MouseEvent.CLICK, showVid1);

function showVid2 (evt:MouseEvent): void{
vidComp.source = "videos/Arrow View_NoBars.flv";
}
btn_vid2.addEventListener (MouseEvent.CLICK, showVid2);

function showVid3 (evt:MouseEvent): void{
vidComp.source = "videos/Arrow Engine_NoBars.flv";
}
btn_vid3.addEventListener (MouseEvent.CLICK, showVid3);

function showVid4 (evt:MouseEvent): void{
vidComp.source = "videos/Arrow Aerobics_NoBars.flv";
}
btn_vid4.addEventListener (MouseEvent.CLICK, showVid4);

function showVid5 (evt:MouseEvent): void{
vidComp.source = "videos/Arrow Launch_NoBars.flv";
}
btn_vid5.addEventListener (MouseEvent.CLICK, showVid5);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum