2010-03-31 3 views
0

J'ai 2 actions dans un fichier Flash que je voudrais tester pour la conversion. L'un est l'ouverture d'un lien dans un onglet/fenêtre, l'autre chargement du contenu dans un iframe Colorbox sur la page.Choisir une action aléatoire, Flash AS3

Comment choisir au hasard l'une des actions suivantes?

J'écoute actuellement un clic sur un bouton:

clickJoin.addEventListener(MouseEvent.CLICK,toJoin); 

Mes deux actions sont:

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

et

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"}); }}) 
'); 

Répondre

1

Pour choisir au hasard entre deux options utilisent Math.random() comme ceci:

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