A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Random numbers

  1. #1
    Junior Member
    Join Date
    May 2001
    Posts
    16
    Hi, I'm trying to make a dynamic text box display a string of 4 or 5 numbers that rapidly change at random. I'm beginning to think that a text box may not be the way to accomplish this, but I'm at a loss. I've referenced my books, and the FLA's here on Flashkit, but just can't seem to find quite what I'm looking for. Any ideas? Thanks a lot for the help.

  2. #2
    Senior Member
    Join Date
    Nov 2000
    Posts
    168
    onClipEvent (enterFrame) {
    _root.text = random(9)+random(9)+random(9)+random(9);
    }

    -you can put this code in an empty mc on the main timeline with your text box.

    -dan

  3. #3
    Senior Member
    Join Date
    Apr 2001
    Posts
    433
    What you need to do is use something very similar to what stork wrote, but instead:

    _root.text = random(10).toString() + random(10).toString() + random(10).toString() + random(10).toString() + random(10).toString()

    Otherwise, it will just add up all the numbers and will generate a number between 0 and 8, not 0 and 9

  4. #4
    Senior Member
    Join Date
    Nov 2000
    Posts
    168
    sorry,

    actually doing it that way will add the numbers. You will have to make five different text boxes and then you could do it like this:

    -declare this function

    function randomize(number){
    _root.text[number] = random(9);
    }



    onClipEvent (enterFrame) {
    randomize(1);
    randomize(2);
    etc. for how ever many text boxes you have
    }

    dan

  5. #5
    Senior Member
    Join Date
    Nov 2000
    Posts
    168
    you read my mind arctic!

  6. #6
    Senior Member
    Join Date
    Apr 2001
    Posts
    433

    Yeah, I do that sometimes (bad telepathy! bad!!)

  7. #7
    Junior Member
    Join Date
    May 2001
    Posts
    16

    Thanks

    Hey that's great. Thanks to both of you.

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