Redirect to new url when flash video ends

Hi, flash noob here. I would like to embed a video into a flash file, and then embed the swf in an html. What I want to happen is that when the video ends, it redirects the user to another URL in the same browser window. Any help?

Thanks!

If your embedding the video direct onto the timeline then all you need to do is create a blank key frame just after the last frame of your video and then add getURL code
Example:


getURL("yourpage.html","_self")

and how could you add random URL’s when flash video ends so that user gets randomly to different parts of a website?

any tips/hints appreciated!
thanks

Put the urls in an array and pull one out using a randomly generated number as the array index


function randRange(min:Number, max:Number):Number {
   // Generate a number between and including min – max
   var randomNum:Number = Math.floor(Math.random()*(max-min+1))+min;
   return randomNum;
   }

//build array to hold url's
  var urlArray:Array = new Array();
  urlArray[0] = "url1";
  urlArray[1] = "url2";
  urlArray[2] = "url3";
  urlArray[3] = "url4";
  urlArray[4] = "url5";
  // Get random number created
  var n:Number = randRange(0, urlArray.length);
  // 
   getURL(urlArray[n], "_self");

Something like that maybe

What I have tried so far is the following:

var urls : Array = ['http://inkenrohweder.com/?page_id=119','http://inkenrohweder.com/?page_id=26','http://inkenrohweder.com/?page_id=121','http://inkenrohweder.com/?page_id=123','http://inkenrohweder.com/?page_id=125']
var index:Number = Math.floor(Math.random() * urls.length))
url = urls[index]

and I’ve added the following as on a button:

on (release){
getURL(url, window);
}

however, I get a syntax error. Would any of you see on the fly what is missing in the above?

ta, in the meantime I have a go what Paul has suggested,

Paul, this has worked a treat! thanks :slight_smile: is there also a way to set random URLs on a “skip intro” button?


function randRange(min:Number, max:Number):Number {
   // Generate a number between and including min – max
   var randomNum:Number = Math.floor(Math.random()*(max-min+1))+min;
   return randomNum;
   }
 
//build array to hold url's
  var urlArray:Array = new Array();
  urlArray[0] = "url1";
  urlArray[1] = "url2";
  urlArray[2] = "url3";
  urlArray[3] = "url4";
  urlArray[4] = "url5"

someButton.onRelease=function(){
var n:Number = randRange(0, urlArray.length)
getURL(urlArray[n], "_self");
}

Something like that.

More examples of using random here.

Hi Paul,

thanks also for supplyting the AS code for adding random hyperlinks to a button. I have tried this and when testing i don’t get any errors but it seems like the links are not going anywhere.

Basically I use the first AS for the automated re-direct as quoted by you on its own layer on the timeline:

function randRange(min:Number, max:Number):Number {   // Generate a number between and including min – max   var randomNum:Number = Math.floor(Math.random()*(max-min+1))+min;   return randomNum;   }
//build array to hold url's  var urlArray:Array = new Array();  urlArray[0] = "url1";  urlArray[1] = "url2";  urlArray[2] = "url3";  urlArray[3] = "url4";  urlArray[4] = "url5";  // Get random number created  var n:Number = randRange(0, urlArray.length);  //    getURL(urlArray[n], "_self");

and on the next layer i add the following AS enabling to click the animation and get directed to random URLS:

can you see with that where I’m going wrong? Do you need the link of where the animation is placed?

thanks a lot for your help,

best, Daniela

If your using/declaring the same code on different layers then there is likely to be a conflict. Can you post your fla?

here is the link to download the zipped version of the fla.

http://inkenrohweder.com/intro_inkenrohweder.zip

Let me know when you have downloaded it so I can remove it again from the server. thanks!

Got it thanks

You had a duplicate array and function.
http://www.scotflash.co.uk/share/intro_inkenrohweder.zip

alright, i just tried to open it but maybe you saved it in a newer version of flash? am still working with flash 8 … I get an unexpected file error when trying to open it

Ok that’s going back a bit. I am using CS5.5

Just place the code on the last frame with what is below


// Get random number created  
var n:Number = randRange(0, urlArray.length);
//    
getURL(urlArray[n], "_self");
stop()

so basically it was just adding a stop() at the end of the AS in last frame? that’s what i’ve done now. however, the animation works, clicking the button still doesn’t work and when the animation has finished no random redirect to url’s is happening.

Ah yeah sorry you need to give the button an instance name “someButton”

super duper! it works a treat now, thanks so much for your help!

nice one :slight_smile:

Paul, hello! or anyone else who has an idea :slight_smile:
with the piece of flash you helped me with (see above) we are experiencing a random “undefined” URL error.
I’m attaching a screenshot.
Any ideas what this is causing?
thanks
Daniela.