Random event between A & B functions on button release?

  • CE/ Pyrocy
  • Proficient
  • Proficient
  • User avatar
  • Joined: Jul 14, 2006
  • Posts: 374
  • Loc: Santa Barbara, CA
  • Status: Offline

Post September 16th, 2009, 10:01 pm

How do I use AS2 to make a button event choose either to go to URL #1 or URL #2 randomly choosing either one 50% of the time.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post September 16th, 2009, 10:01 pm

  • IceCold
  • Guru
  • Guru
  • User avatar
  • Joined: Nov 05, 2004
  • Posts: 1254
  • Loc: Ro
  • Status: Offline

Post September 17th, 2009, 4:52 am

I think this is a fairly 50% chance :)
Code: [ Select ]
var randNumber = Math.ceil(Math.random()*100);
if (randNumber < 50)
 getURL(url1);
else
getURL(url2);
  1. var randNumber = Math.ceil(Math.random()*100);
  2. if (randNumber < 50)
  3.  getURL(url1);
  4. else
  5. getURL(url2);
“True mastery transcede any particular art. It stems from mastery of oneself - the ability, developed throgh self-discipline, to be calm, fully aware, and complety in tune with oneself and the surroundings. Then, and only then, can a person know himself. ”
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Joined: May 28, 2003
  • Posts: 23404
  • Loc: Woodbridge VA
  • Status: Offline

Post September 17th, 2009, 5:30 am

This works also (put your URL's in an array and randomize the array)

ACTIONSCRIPT Code: [ Select ]
on (release)  {
   
      link_arr = ["www.ozzu.com", "www.google.com"];
        ranNum = Math.floor(Math.random()*link_arr.length);
        getUrl("http://" + link_arr[ranNum]);
}
  1. on (release)  {
  2.    
  3.       link_arr = ["www.ozzu.com", "www.google.com"];
  4.         ranNum = Math.floor(Math.random()*link_arr.length);
  5.         getUrl("http://" + link_arr[ranNum]);
  6. }


I think the inherent nature of random makes that about 50/50 kinda like the toss of a coin with only two URI's. And of course you can add as many URI's as you want to your array.
"There's no place like 127.0.0.1 except for ::1."
Alexandria Networks. Leader in IT consulting for associations/non-profits, and small to medium sized businesses around the northern Virginia and Washington D.C. metro area.

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 45 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.