A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Random frame

Hybrid View

  1. #1
    Junior Member
    Join Date
    Feb 2004
    Posts
    6

    Random frame

    I have a button that generates a random number. Now I want the game to check the variable and go to that frame.

    code:
    if (rand = 2) {
    gotoAndPlay(2);
    }


    The variable is on a dynamic text box called rand.

    Something like that. Any ideas?

    EDIT: BTW, I'm using Flash 5.
    Last edited by stephans; 10-23-2004 at 10:18 PM.

  2. #2
    Junior Member
    Join Date
    May 2004
    Location
    Springfield, OR
    Posts
    21
    im not too sure what you are asking, but i think you want a one-in-two chance of the main movie to goto frame 2 when you click on the button. so give the button this script:
    (its the depricated way but you'r using flash 5, right?)

    on (press) {
    randomizer = random(2);
    if (randomizer == "0") {
    gotoAndStop(2);
    }
    }

    there, think that should do it for you.

    now, if that wasn't what you wanted, i think this might be:
    you want a text box that teh viewer can type into, and on the press of a button go to frame 2 if the viewer typed in 2.

    make an input text box that has no instance name, but a variable name of typehere. then give the button this script:

    on (press) {
    if (typehere == "2") {
    gotoAndStop(2);
    }
    }

    try to explain it better next time.

  3. #3
    Junior Member
    Join Date
    Feb 2004
    Posts
    6
    Oops... My bad... Heh it looked good when I posted it. Yea. I think my problem was i forgot to use ==, I just had =.

    Heres a more detailed explanation,

    I have a button. When you click it I want to go to a random frame (within the button)and play a sound. There are 5 sounds so the random would be (5).

    code:
    on (press) {
    randomizer = random(5);
    if (randomizer == "0") {
    gotoAndPlay(3);
    }
    }



    That's what it would be. I'll test that now.

  4. #4
    Junior Member
    Join Date
    Feb 2004
    Posts
    6
    So far it only works when rand == 1. Heres the code I have to far.
    code:
    rand = random(5) + 1;
    gotoAndStop(1);
    if (rand == "1") {
    gotoAndPlay(3)
    }

    if (rand == "2") {
    gotoAndPlay(11)
    }



    EDIT: Nevermind! It works now! Thanks for your help!
    Last edited by stephans; 10-24-2004 at 01:04 AM.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center