Professional Web Applications Themes

a random und array problem - Macromedia Flash Actionscript

Hi you there. I?ve got a problem and I hope you could help me.... I?ve got a button on the screen and when I push it I?d like to display a value from an array called "arrayRnd" into a dynamic text called "displayRnd" randomly. In the code below I wrote the values from the array, but here come the problems: Sometimes I push it and I get the same value I had before, I mean the value repeates it self, and sometimes I get neither value!, displayRnd doesn?t display any value such "a","b","c", etc, and when I said any value ...

  1. #1

    Default a random und array problem

    Hi you there. I?ve got a problem and I hope you could help me....
    I?ve got a button on the screen and when I push it I?d like to display a value
    from an array called "arrayRnd" into a dynamic text called "displayRnd"
    randomly.
    In the code below I wrote the values from the array, but here come the
    problems:
    Sometimes I push it and I get the same value I had before, I mean the value
    repeates it self, and sometimes I get neither value!, displayRnd doesn?t
    display any value such "a","b","c", etc, and when I said any value I mean the
    dynamic text showes actually empty.

    here the code:

    arrayRnd = new Array("a","b","c","d","e","f","g","h");
    ButtonRnd.onRelease = function(){
    rndNum = Math.round(Math.random()*(arrayRnd.length));
    displayRnd.text = arrayRnd[rndNum];
    }
    I thought to add this line to fix the problem:
    ....
    currentRnd = rndNum
    if(rndNum = currentRnd){
    rndNum = Math.round(Math.random()*(currentRnd));
    }

    but this doesn?t work.

    I?ll wait for yours sugestions, thanks
    Alvaro.

    ps. sorry about my english :)


    Ratw? Guest

  2. #2

    Default Re: a random und array problem

    The problem here is that you can get 8 which of course won't work as an array
    index. So I would try this

    displayRnd.text=arrayRnd[random(arrayRnd.length)];


    this will always give you a legal index. random and Math.random are not the
    same thing. Check you help


    Jim Esteban Guest

Similar Threads

  1. #26289 [NEW]: Random problem in mail() function
    By julien at touslesdrivers dot com in forum PHP Development
    Replies: 0
    Last Post: November 17th, 04:12 PM
  2. random subarray from an array
    By Ante Perkovic in forum PHP Development
    Replies: 1
    Last Post: October 5th, 11:18 PM
  3. random array
    By Willem van Isselmuden in forum Macromedia Flash
    Replies: 0
    Last Post: September 21st, 09:49 PM
  4. Random Array values
    By mike in forum PHP Development
    Replies: 0
    Last Post: July 14th, 03:42 PM
  5. Problem with random array
    By noone in forum PHP Development
    Replies: 3
    Last Post: July 7th, 04:02 AM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139