views:

62

answers:

2

I have 2 actions in a Flash file that I would like to test for conversion. One is opening a link in a tab/window, the other loading the content in a Colorbox iframe over the page.

How do I randomly choose one of the following actions?

I currently listen for a click on a button:

clickJoin.addEventListener(MouseEvent.CLICK,toJoin);

My two actions are:

navigateToURL(new URLRequest("http://www.google.com/"), '_blank');

and

ExternalInterface.call('$.fn.colorbox({
    href: "http://www.google.com/",
    width:"80%",
    height:"80%",
    iframe:true,
    onLoad:function(){ $("#player").css({"visibility":"hidden"}); },
    onClosed:function(){ $("#player").css({"visibility":"visible"}); }})
');
+2  A: 

To randomly choose between two options use Math.random() like this:

if (Math.random() < 0.5) {
    // do action 1
} else {
    // do action 2
}
Sam
A: 

BTW: the ExternalInterface.call will only work in AS3 if everything inside the single quotes is in one continuous line. Also, note that you cannot delete the last line entirely because the double curly bracket is in that line... so don't erase anything after that.

Bill