Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2008
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Actionscript 3 videos onLoad random playback

    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!

  • #2
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Do you have any code now? It would just be picking a random value or randomly sorting the array of videos.
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #3
    New Coder
    Join Date
    Dec 2008
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Code

    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.

    Code:
     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);


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •